用C语言求三个数的平均值

如题所述

考虑到是初学者,所以用最简单的思路来一个程序,定义四个变量,三个变量用于存储输入的三个数,第四个变量用于存储所求的平均数。

代码如下:

int main()

{

int a=0,b=0,c=0,average=0;

scanf("%d %d %d",&a, &b, &c);

average = (a+b+c)/3;

printf("%d", average);

return 0;

}

下图中有注释于结果测试:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-03-10
main()
{
float a,b,c,av;
printf("please input 3 number@s:");
scanf("%f%f%f",&a,&b,&c);
av=(a+b+c)/3.0;
printf("平均数是:%f\n",av);
}
有什么问题,请留言追问。
第2个回答  2019-03-10
#include<stdio.h>
#include<stdlib.h>

int main()
{
float ave,temp;

printf("请输入3个数:");
scanf("%f %f",&ave,&temp);
ave+=temp;
scanf("%f",&temp);
ave+=temp;
ave/=3;
printf("平均值是:%f\n",ave);
system("PAUSE");
return 0;
}
第3个回答  2019-03-10

c语言对数据类型要求太死板了

class input_test(object):
    def inputing(self,x,y,z):
        print("this is a program\n")
        result = (x + y + z) / 3
        return 'the avg is '+str(result)
if __name__ == '__main__':
    x = int(input("please input the first number,then press Enter\n"))
    y = int(input("please input the second number,then press Enter\n"))
    z = int(input("please input the third number,then press Enter\n"))
    program = input_test()
    print(program.inputing(x,y,z))

本回答被网友采纳