求输入100个数中正数的个数及其平均值
main( )
{int i,n;
float sum,f;
n=0;
__1__;
for(i=0;i <= 100,i++)
{printf("enter a real number:";
scanf("%f",&f));
if__2__
continue; __3__;
n++;
}
print f("sum=%f",sum);
print f("a rerage=%f",sum/n);
}
main( )
{int i,n;
float sum,f;
n=0;
__1__;
for(i=0;i <= 100,i++)
{printf("enter a real number:";
scanf("%f",&f));
if__2__
continue; __3__;
n++;
}
print f("sum=%f",sum);
print f("a rerage=%f",sum/n);
}
举一反三
- 编程:求n个数的和。首先输入一个整数n,然后输入n个整数,求它们的和。部分程序如下: #include int main(void) { int number, sum; int i, n; sum = 0; scanf("%d", &n); for(i = 1; i <= n; i++) { scanf("%d", &number); } printf("%d\n", sum); return 0; }
- 输入一个正整数给变量n,求1到n的所有正整数之和。不正确的程序是()。 A: #includevoidmain(){inti,n,sum;scanf("%d",&n);for(i=1,sum=0;i<=n;i++)sum=sum+i;printf("%d",sum);} B: #includevoidmain(){inti,n,sum=0;scanf("%d",&n);for(i=1;i<=n;i++)sum=sum+i;printf("%d",sum);} C: #includevoidmain(){inti,n,sum;scanf("%d",&n);for(i=1;i<=n;i++)sum=sum+i;printf("%d",sum);} D: #includevoidmain(){inti,n,sum;scanf("%d",&n);for(i=1,sum=0;i<=n;)sum=sum+i,i++;printf("%d",sum);}
- 以下程序的输出是() int main(){ int i,sum=0; for(i=0;i<=100;i++)sum=sum+i; printf("sum=%d\n",sum); return 0; }
- 下面程序可以正确求出1+2+3+。。。+n的和。() #include int main( ) { int i = 1,sum = 0,n; scanf(“%d”,&n); while (i <= n) sum = sum + i; ++i; printf("sum=%d
- include stdio h define SUM 100000int main float amount aver total int i for i 1 total 0 i 1000 i printf please enter amount scanf f amount total total amount if total SUM break aver total i printf num d naver 10 2f n i aver return 0