C 练习实例100
C 语言教程
· 2019-02-22 18:58:37
题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件"stud"中。
程序分析:无。
程序源代码:
实例
// Created by www.codercto.com on 15/11/9.
// Copyright © 2015年 码农教程. All rights reserved.
//
#include<stdio.h>
#include<stdlib.h>
typedef struct{
int ID;
int math;
int English;
int C;
int avargrade;
char name[20];
}Stu;
int main()
{
FILE*fp;
Stu stu[5];
int i,avargrade=0;
printf("请输入5个同学的信息:学生号,姓名,3门成绩:\n");
for(i=0;i<5;i++)
{
scanf("%d %s %d %d %d",&(stu[i].ID),stu[i].name,&(stu[i].math),&(stu[i].English),&(stu[i].C));
stu[i].avargrade=(stu[i].math+stu[i].English+stu[i].C)/3;
}
if((fp=fopen("stud","w"))==NULL)
{
printf("error :cannot open file!\n");
exit(0);
}
for(i=0;i<5;i++)
fprintf(fp,"%d %s %d %d %d %d\n",stu[i].ID,stu[i].name,stu[i].math,stu[i].English,
stu[i].C,stu[i].avargrade);
fclose(fp);
// system("pause");
return 0;
}
以上实例运行输出结果后:
请输入5个同学的信息:学生号,姓名,3门成绩: 1 a 60 70 80 2 b 60 80 90 3 c 59 39 89 4 e 56 88 98 5 d 43 88 78
打开 stud文件,内容如下
1 a 60 70 80 70 2 b 60 80 90 76 3 c 59 39 89 62 4 e 56 88 98 80 5 d 43 88 78 69
点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html
Approximation Algorithms
Vijay V. Vazirani / Springer / 2001-07-02 / USD 54.95
'This book covers the dominant theoretical approaches to the approximate solution of hard combinatorial optimization and enumeration problems. It contains elegant combinatorial theory, useful and inte......一起来看看 《Approximation Algorithms》 这本书的介绍吧!