Home > Back-end >  Bosses the zha write ah, the head is rotten
Bosses the zha write ah, the head is rotten

Time:09-23

Build file 111. TXT, data are 12 23 44, 68, 95, 68 47 95 10 25
Program, the data file, between a third and ninth data, the maximum value can be divided exactly by 2,

CodePudding user response:

#include
#include

# define MAXLINE 1024
Int main () {
Int num [10].
int index=0;
Char STR [1024].
111. TXT FILE * fp=fopen (" ", "r");
If (fp==NULL) {
Printf (" always open a file \ n ");
return 0;
}
The fgets (STR, MAXLINE, fp);
Char * arr=strtok (STR, "");
While (arr)
{
Num [index]=atoi (arr);
Printf (" % d ", num [index]);
Printf (" % s \ n ", arr);
Arr=strtok (NULL, "");
index++;
}
Int Max=0;
for(int i=2; i<9. I++) {
If (num [I] % 2==0) {
If (num [I] & gt; Max) {
Max num=[I];
}
}
}
Printf (" between the third and ninth data, the maximum value can be divided exactly by 2: % d \ n ", Max).
return 0;
}

CodePudding user response:

This is a two-step,
Step is to file operations, step is data manipulation, not impatient oh,
  • Related