标签:main log stdio.h htm int out color scan average
#include<stdio.h> int main() { int n,i,t=1; float sum=0; scanf("%d",&n); for(i=1;i<=n;i++) { sum=sum+(float)i/(2*i-1)*t; t=-t; } printf("%.3f",sum); return 0; }
#include<stdio.h> int main() { int n,i,a,sum=0,f=0; float d; scanf("%d\n",&n); if(n>0){ for(i=1;i<=n;i++) { scanf("%d",&a); if(a>=60) f=f+1; sum=sum+a; } d=sum/(float)n; printf("average = %.1f\n",d); printf("count = %d",f); } else printf("average = 0.0");
printf("count = 0.0"); return 0; }
解决方法:在输入n后,判断n是否小于等于零,如果是,则直接输出average = 0.0 count = 0.0
上传截图:
博客字数 | 时间 | 代码行数 | 时间 | 知识点 |
100 | 3H | 105 | 1H | ———— |
标签:main log stdio.h htm int out color scan average
原文地址:http://www.cnblogs.com/boke2017boke/p/7856300.html