程序读入20个整数,统计非负数个数,并计算非负数之和。
#include <stdio.h>
main( )
{ int i, a[20], s, count;
s=count=0;
for(i=0; ; i++)
scanf(“%d”, &a[i] );
for(i=0; i<20; i++)
{ if( a[i]<0 ) continue ;
;
count++;
}
printf(“s=%d\t count=%d\n”, s, count”);
i<20
s+=a[i]
s = s+a[i]
i < 20
s += a[i]
s=s+a[i]
1.i<20 2.s+=a[i]
i < 20 s += a[i]
i<20 s+=1
i<20 s=s+a[i]
else
i<20 elsr
i<20 s+=a[i]
int arr[20]; int sum = 0; int count = 0; for (int i = 0; i < 20; ++i) { scanf("%d", &arr[i]); } for (int i = 0; i < 20; ++i) { if (arr[i] >= 0) { sum += arr[i]; count++; } } printf("非负数之和:%d\n", sum); printf("非负数个数:%d\n", count);
for(i=0; i<20 ; i++)
s+=a[i] ;
#include main( ) { int i, a[20], s, count; s=count=0; for(i=0; i<20; i++) scanf(“%d”, &a[i] ); for(i=0; i<20; i++) { if( a[i]<0 ) continue ; s+=a[i] ; count++; } printf(“s=%d\t count=%d\n”, s, count”); }
i<=20
过
i<20 else
,
i<20
for(i=0;i<20; i++)
scanf('%d', &a[i] );
{
if (a[i]<0) continue;
s+=a[i];
printf('s=%d\t count=%d\n', s, count”);
题中的if判断写错了改为a[i]>=0 i < 20
s = s +a[i]
int main( ){
int i, a[20], s, count; s=count=0; for(i=0;i<20; i++) scanf("%d", &a[i]);
s=s+a[i]; count++;
printf("s=%d\t count=%d\n", s, count);
i < 20,s = s + a[i] ,
else:
1.i<20
2.s+=a[i]
i<20 s+=a[i]
i<20 s++
i<20;
s=s+a[i];
应该是a[i]>=0吧
i<20 s=s+a[i]
i<20 s+=i
for(i=0; i< 20; i++)
s += a[i];
else s=s+a[i]
else s+=a[i];
#include &l...
用户登录可进行刷题及查看答案
登录后提交答案