C语言中,编程统计文件wj5.txt中偶数元素的个数。

Python012

C语言中,编程统计文件wj5.txt中偶数元素的个数。,第1张

#include<stdio.h>

main()

{

int num,count=0

FILE *fp=fopen("wj5.txt","r")

while (!feof(fp))

{

fscanf(fp,"%d",&num)

if (num%2==0)count++

}

fclose(fp)

printf("偶数%d个\n",count)

}

//#include "stdafx.h"//vc++6.0加上这一行.

#include "stdio.h"

#include "time.h"

#include "stdlib.h"

int main(void){

int nDec[100],i,j,k

srand((unsigned)time(NULL))

for(i=0i<100nDec[i++]=rand())

for(i=0i<100i++){

for(k=i,j=k+1j<100j++)

if(nDec[k]<nDec[j]) k=j

if(i!=k){

j=nDec[i]

nDec[i]=nDec[k]

nDec[k]=j

}

printf("%d ",nDec[i])

}

printf("\n")

return 0

}