Answer to Question #199238 in C for Pragadeesh

Question #199238

Write a C program to find the sum of positive negative elements in an array.


1
Expert's answer
2021-05-27T06:25:55-0400
#include<stdio.h>
int main()
{
    int n,i,sum_positive=0,sum_negative=0;
    printf("Enter the number of elements in the array : ");
    scanf("%d",&n);
    int arr[n];
    printf("Enter the elements of the array : ");
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<n;i++)
    {
        if(arr[i]>0)
        {
            sum_positive=arr[i]+sum_positive;
        }
        else
        {
            sum_negative=arr[i]+sum_negative;
        }
    }
    printf("Sum of positive numbers in the array = %d",sum_positive);
    printf("\nSum of negative numbers in the array = %d",sum_negative);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS