lyhk.net
当前位置:首页 >> 输入3个整数 求平均值 >>

输入3个整数 求平均值

#include<stdio.h> void main() { int a,b,c,s; float av; scanf("%d%d%d",&a,&b,&c); s=a+b+c; av=s/3f; printf("%d %f\n",s,av); }

#include<stdio.h>int main(){double a,b,c; //定义三个整数double ave; //定义平均值scanf("%d%d%d",&a,&b,&c); // 输入三个整数ave=(a+b+c)/3; //求平均值printf("平均数是%f",ave); //输出return 0;}

#include <stdio.h>int main() { int a,b,c,sum; double avg; printf("输入三个数:"); scanf("%d%d%d",&a,&b,&c); sum = a+b+c; avg = sum/3.0; printf("和:%d\n",sum); printf("平均值:%lf\n",avg); return 0; }

#include "stdio.h" int main(int argc,char *argv[]){ int a,b,c,t; printf("Please enter 3 integers\n"); scanf("%d%d%d",&a,&b,&c); if(a>b) t=a,a=b,b=t; if(a>c) t=a,a=c,c=t; if(b>c) t=b,b=c,c=t; printf("The AVE is %f\n%d %d %d\n",(a+b+c)/3.0,a,b,c); return 0; }运行样例:

#include int main() { int n,i,j; double sum=0; scanf("%d",&n);//输入整数的个数. for(i=0;i

int num1,num2,num3; float average; printf("please num1,num2,num3:\n"); scanf("%d,%d,%d",&num1,&num2,&num3); average = (num1+num2+num3)/3.0; printf("%6.2f\n",average); //注:数字之后不要有空格

123456 #include<stdio.h> voidmain() { inta,b,c,s; floatav; scanf("%d%d%d",&a,&b,&c); s=a+b+c; av=s/3f; printf("%d %f\n",s,av); }

#include int main(){ printf("请输入三个整数(中间以空格隔开):\n"); int a, b, c; int t; scanf("%d %d %d", &a, &b, &c); if (a > b) { t = a; a = b; b = t; } if (a > c) { t = a; a = c; c = t; } if (b > c) { t = b; b = c; c = t; } printf("%d %d %d %f", a, b, c, (a+b+c)/3.0); return 0;}

程序代码如下:#include <stdio.h> int main() { int a,b,c,average; printf("a="); scanf("%d",&a); printf("b="); scanf("%d",&b); printf("c="); scanf("%d",&c); average=(a+b+c)/3; printf("a,b,c3个数字的平均值:%d",average); } 扩展

#include <stdio.h>int main (void){int a, b ,c ,sum; double p;printf("请输入三个整数用逗号隔开:");scanf("%d,%d,%d",&a,&b,&c);sum=a+b+c;p=sum/3.0;printf("和sum=%d\n",sum);printf("平均数p=%f\n",p);return 0;}

mtwm.net | gtbt.net | ddgw.net | bestwu.net | zdly.net | 网站首页 | 网站地图
All rights reserved Powered by www.lyhk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com