FY_BCA_C_SLIP_25




/* slip no : 25_1 write a prog to accept n nubers and display sum of all +ve and -ve numbers  */

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

int main()
{
                int a[20],n,i,psum,nsum;
                printf("\n Enter how many nos : ");
                scanf("%d",&n);
                for(i=0;i<n;i++)
                {
                                printf("\n Enter element ");
                                scanf("%d",&a[i]);
                }
                psum=nsum=0;
                for(i=0;i<n;i++)
                {
                                if(a[i]%2==0)
                                psum = psum+a[i];
                                else
                                nsum = nsum+a[i];
                }
                printf("\n Sum of positive no is = %d",psum);
                printf("\n Sum of negative no is =%d",nsum);
                getch();
}

No comments:

Post a Comment