Wednesday, 8 April 2015

C Program to accept 'n' numbers and find the sum of all +ve and -ve numbers WITHOUT USING ARRAYS.

#include<stdio.h>
#include<conio.h>
main()
{
                int n,i,x,s=0,sum=0;
                clrscr();
                printf("Enter the number of terms:\n");
                scanf("%d",&n);
                for(i=1;i<=n;i++)
                {
                                printf("Enter the number :\n");
                                scanf("%d",&x);
                                if(x>0)
                                {
                                                s=s+x;
                                }
                                else
                                {
                                                sum=sum-(-x);
                                }
                }
                printf("\n\tSum of Positive numbers is %d\n\tSum of negative numbers is %d",s,sum);
}

No comments:

Post a Comment