CALCULATE SUM OF POSITIVE NUMBERS FROM N NUMBERS
In this program we learn how to calculate sum of positive numbers from n numbers provided by user using C.C program to calculate sum of positive numbers from n numbers
// Calculate sum of positive numbers from n numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int i,N,sum=0,m;
clrscr();
printf("\n Enter how many numbers : ");
scanf("%d",&N);
printf("\n Enter %d numbers : ",N);
for(i = 1; i <= N; i++)
{
scanf("%d",&m);
if(m >= 0)
sum = sum + m;
}
printf("\n Sum of positive numbers = %d",sum);
getch();
}
OUTPUT:
Enter how many numbers : 5
Enter 5 numbers : 4 -1 -8 11 6
Sum of positive numbers = 21
Enter 5 numbers : 4 -1 -8 11 6
Sum of positive numbers = 21
No comments:
Post a Comment