Program for +ve count, -ve count, +ve sum and -ve sum - C-Tutorial

Latest

Sunday, 8 December 2019

Program for +ve count, -ve count, +ve sum and -ve sum


/* Program for +ve count, -ve  count, +ve sum and -ve sum */

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

void main()
{
int i,a[50],n, pc=0, nc=0, psum=0, nsum=0;

clrscr();

printf("\n Enter the n value: ");
scanf("%d",&n);
printf("\n Enter the %d array elements: ",n);
for(i=0 ;i<=n-1; i++)
scanf("%d",&a[i]);

for(i=0; i<=n-1; i++)
{
if(a[i] >= 0)
{
pc++;
psum = psum + a[i];
}
else
{
nc++;
nsum = nsum + a[i];
}
}

printf("\n positive count = %d, negitive_count=%d, positive_summ=%d, negtive_sum=%d", pc, nc, psum, nsum);

getch();
}

No comments:

Post a Comment