|
发表于 2022-11-10 14:09:59
|
显示全部楼层
- #include <stdio.h>
- struct Student
- {
- char name[10] ;
- double grade ;
- double goal ;
- double score ;
- } a[5] = {{"abc" , 85 , 95 , 98} , {"bcd" , 65 , 91 , 88} , {"cde" , 85 , 89 , 93} , {"def" , 92 , 98 , 99} , {"efg" , 97 , 93 , 90}} ;
- int main(void)
- {
- int i , j , k ;
- double total[5] ;
- for(j = 0 ; j < 5 ; j ++) total[j] = 0.3 * a[j] . goal + 0.5 * a[j] . grade + 0.2 * a[j] . score ;
- printf("%.2f" , total[0]) ;
- for(j = 1 ; j < 5 ; j ++) printf(", %.2f" , total[j]) ;
- printf("\n") ;
- }
复制代码
编译运行实况:
- D:\[00.Exerciese.2022]\C>g++ -o x x.c
- D:\[00.Exerciese.2022]\C>x
- 90.60, 77.40, 87.80, 95.20, 94.40
- D:\[00.Exerciese.2022]\C>
复制代码 |
|