⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 42.c

📁 C程序100练,包含了100个例子的原代码,面向初学者
💻 C
字号:
#include <stdio.h>
#include <conio.h>
/*文件包含*/
#define MAX 100
/*宏定义*/
int xx[MAX];
/*定义数组*/
int totnum=0;
int totcnt=0;
double totpjz=0.0;
/*变量定义*/
int readdat(void);
void writedat(void);
/*函数声明*/
void calvalue(void)
{
int i;
int j;
long val=0;
for(i=0;i<MAX;i++)
if(xx[i])
totnum++;
/*正整数个数统计*/
for(i=0;i<totnum;i++)
{
j=(xx[i]>>1);
if(j%2==0)
{
totcnt++;
val+=xx[i];
}
}
totpjz=(double)val/totcnt;
/*计算平均值*/
}
main()
{
clrscr();
/*调用清屏函数*/
if(readdat())
{
printf("the file cann't open!\007\n");
return;
}
calvalue();
printf("the totnum is %d\n",totnum);
printf("the totcnt is %d\n",totcnt);
printf("the totpjz is %.2lf\n",totpjz);
/*输出提示信息*/
writedat();
/*调用函数*/
getch();
}
int readdat(void)
/*读文件函数*/
{
FILE *fp;
/*定义文件指针*/
int i=0;
if((fp=fopen("in.dat","r"))==NULL)
return 1;
while(!feof(fp))
/*读到文件结束*/
{
fscanf(fp,"%d",&xx[i++]);
/*读文件内容*/
}
fclose(fp);
/*关闭文件*/
return 0;
}
void writedat(void)
/*写文件函数*/
{
FILE *fp;
fp=fopen("my4.dat","w");
/*打开文件*/
fprintf(fp,"%d\n%d\n%.2lf\n",totnum,totcnt,totpjz);
/*写文件*/
fclose(fp);
/*关闭文件*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -