我的祖国我的家乡征文:输入N个数,直到遇到0停止,输出正数
来源:百度文库 编辑:高考问答 时间:2024/04/29 02:46:15
输入N个数,直到遇到0停止,输出所有正数的和
#include <stdio.h>
void main()
{
long sum = 0;
long temp = 0;
printf("enter numbers, 0 to stop : \n");
scanf("%ld", &temp);
while(temp != 0)
{
if(temp > 0)
sum += temp;
scanf("%ld", &temp);
}
printf("sum of all positive numbers : %ld\n", sum);
}