#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;
} #include<stdio.h>
int main(void){
float math, english, chinese; // 分别用来存储三科的成绩
float sum_score = 0, avg_score = 0; // 用来保存三科成绩和以及平均数
scanf("%f %f %f", &math, &english, &chinese); // 从键盘获取三个分数
sum_score = math + english + chinese; // 求三科成绩的和
avg_score = sum_score / 3; // 求三科成绩的平均数
printf("%.2f %.2f\n", sum_score, avg_score); // 打印输出三科成绩和 三科的平均数 每个数字保留2位小数
return 0;
}
题目简单,没啥难度,加油,向编程高手前进吧
#include<stdio.h>
int main()
{
float a,b,c;
scanf("%f%f%f",&a,&b,&c);
printf("%.2f %.2f\n",a+b+c,(a+b+c)/3);
return 0;
}