SUM OF POSITIVE AND NEGATIVE NUMBERS IN GIVEN ARRAY - C-Tutorial

Latest

Monday, 26 September 2016

SUM OF POSITIVE AND NEGATIVE NUMBERS IN GIVEN ARRAY

/* SUM OF POSITIVE AND NEGATIVE NUMBERS IN GIVEN ARRAY */


#include<stdio.h>
#include<conio.h>

main()
{
int i,n,a[10],psum=0,nsum=0;
clrscr();
printf("\n Enter n value:");
scanf("%d",&n);
printf("\n Enter the +ve and -ve array elements:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]>0)
{
psum=psum+a[i];
}
else
{
nsum=nsum+a[i];
}
}
printf("\n The sum of positive array is:%d",psum);
printf("\n The sum of negative array is: %d",nsum);

getch();
}

No comments:

Post a Comment