某一學生修國文、計算機概論、計算機程式設計三科, 使用者輸入名字(一個char)、學號(integer)、三科成績(double)。 (1) 計算學生總成績、平均。 (2) 印出名字、學號、總成績、平均。 Input K 905067 100 100 100 Output Name: K Id: 905067 Total: 300 Average: 100
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- char name;
- int id,total,average;
- double chinese, compscience, programming,avg,to,avgint;
- scanf("%c ",&name);
- scanf("%d",&id);
- scanf("%lf",&chinese);
- scanf("%lf",&compscience);
- scanf("%lf", &programming);
- to = (programming + chinese + compscience);
- total=to;
- to=to/3;
- avgint=floor(to);
- if(to-avgint>0.5) avg=ceil(to);
- else avg=to;
- average=avg;
- printf("Name:%c\n", name);
- printf("Id:%d\n", id);
- printf("Total:%d\n", total);
- printf("Average:%d\n", average);
- system("PAUSE");
- return average;
- }
Hiç yorum yok:
Yorum Gönder