C program to find sum of positive and negative numbers in an array - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Saturday, February 1, 2020

C program to find sum of positive and negative numbers in an array - My CS Tutorial

C program to calculate positive/negative(+ve and -ve) numbers in an array.

In this post we will learn how to write a c program code to calculate sum of positive and negative integers in an array.

In the first user will enter the size of an array then enter the positive and negative integers.
After it compiler will print the sum of all +ve and -ve integers.


C PROGRAM CODE



#include<stdio.h>
#include<conio.h>
void main()
{
    int size,x,positive=0,negative=0;
    int array[50];
    clrscr();
 
    printf("\n ENTER THE SIZE OF THIS ARRAY:\n ");
    scanf("%d",&size);
 
    printf("\n ENTER POSITIVE AND NEGATIVE NUMBERS TO FIND SUM:\n ");
 
    for(x=0;x<size;x++)
    {
        scanf("%d",&array[x]);

    }
    for(x=0;x<size;x++)
    {
        if(array[x]>0)
        positive=positive + array[x];
        if(array[x]<0)
        negative=negative + array[x];
    }
 
    printf("\n THE SUM OF POSITIVE NUMBERS IS : \n %d",positive);

    printf("\n THE SUM OF NEGATIVE NUMBERS IS : \n %d\n",negative);
 
    getch();
}


OUTPUT:




Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment