C语言 随机输入一批整数(有正数、负数和0,其中至少包含5个正整数),编程计算并且输出这批整数中前5个正整数的和
#include<stdio.h>
int main(){
int a,s=0,cnt=0;
while(scanf("%d",&a)!=EOF){
if(a>0){
s+=a;
cnt++;
if(cnt==5)
break;
}
}
printf("%d",s);
return 0;
}
觉得有用的话采纳一下哈