Created
November 30, 2015 12:15
-
-
Save 6uclz1/08457d61ecd923cdb4d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct student { | |
char name[20]; | |
int score; | |
} student; | |
int main() | |
{ | |
struct student student[5]; | |
int sum = 0, i, ave; | |
for(i = 0; i < 5; i++) { | |
printf("name score? "); | |
scanf("%s %d",student[i].name, &student[i].score); | |
sum = sum + student[i].score; | |
} | |
ave = sum / 5; | |
printf("Average: %d\n", ave); | |
printf("Students of above average:\n"); | |
for(i = 0; i < 5; i++) { | |
if (ave < student[i].score) { | |
printf("%s\n", student[i].name); | |
} | |
} | |
} | |
//mondai21.c | |
#include <stdio.h> | |
int main() | |
{ | |
int i; | |
int num[5]; | |
FILE *fp; | |
fp = fopen("test.txt","w"); | |
for (i = 0; i < 5; i++) { | |
scanf("%d", &num[i]); | |
fprintf(fp,"%d\n", num[i]); | |
} | |
fclose(fp); | |
} | |
//mondai22.c | |
#include <stdio.h> | |
int main() | |
{ | |
int i; | |
int num[5]; | |
FILE *fp; | |
fp = fopen("test.txt", "r"); | |
for(i = 0; i < 5; i++) { | |
fscanf(fp,"%d", &num[i]); | |
printf("%d\n", num[i]); | |
} | |
fclose(fp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment