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

📄 ch27-9.c

📁 C语言程序设计上机指导与练习 冶金工业出版社 刘怀亮
💻 C
字号:
#include <stdio.h>
#include <conio.h>
#define MAXNUM 20

int xx[MAXNUM];
int totNum=0; /*共有多少个正整数*/
int totCnt=0; /*符合条件的正整数的个数*/
double totPjz=0.0;   /*平均值*/

void ReadDat(void);
void writeDat(void);

void CalValue(void)
{
   int i,data;
   for(i=0;i<MAXNUM;i++)
      if(xx[i]>0) 
      {
         totNum++;
         data=xx[i]>>1;
         if(data%2==0)
         {totCnt++;totPjz+=xx[i];}
         }
         if(totCnt==0) 
            totPjz=0;
         else 
            totPjz/=totCnt;
      }
void main()
{
   int i;
   clrscr();
   for(i=0;i<MAXNUM;i++)
      xx[i]=0;
   ReadDat();
   CalValue();
   printf("共有正整数=%d个\n",totNum);
   printf("符合条件的正整数的个数=%d个\n",totCnt);
   printf("平均值=%.2f\n",totPjz);
   writeDat();
}

void ReadDat(void)
{
   int i=0; 
   printf("请输入 %d 个四位的整数:\n", MAXNUM);
   for(i=0;i<MAXNUM;i++)
      scanf("%d,",&xx[i++]);
}

void writeDat(void)
{
   FILE *fp;
   fp=fopen("OUT.DAT","w");
   fprintf(fp,"%d\n%d\n%6.2f\n",totNum,totCnt,totPjz);
   fclose(fp);
}

⌨️ 快捷键说明

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