#include <stdio.h> int main() { double score = 0; double sum = 0; int i = 0; for ( i = 0; i < 3; i++) { scanf("%lf", &score); sum = sum + score; } printf("%.2lf %.2lf", sum, sum/3.0); return 0; }
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <malloc.h> int main() { const int sz = 3;//科目的数量 float* p = NULL; int i = 0; float sum = 0.0f; float age = 0.0f; //开辟空间存放分数 p = (float*)malloc(sizeof(float)); if (!p) { perror("malloc"); return 1; } //录入分数,并进行求和计算 for (i = 0; i < sz; i++) { scanf("%f", p); sum += *p; } age = sum / sz;//平均数计算 //输出 printf("%.2f %.2f\n", sum, age); //释放空间 free(p); p = NULL; return 0; }