C Program to Sum Positive and Negative Numbers in Array

C Program to Sum Positive and Negative Numbers in Array

Write C Program to Sum Positive and Negative Numbers in Array

// C Program to Sum Positive and Negative Numbers in Array

#include <stdio.h>

int main()
{
	int A[] = {1, 2, 3, -1, -2, -3};

	int sum_positive = 0,sum_negative = 0,i,n;

	n = sizeof(A) / sizeof(A[0]);

	printf("Array Elements :--> ");
	for(i=0; i<n; i++)
        printf("%d  ", A[i]);

	for(i = 0;i < n ;i++)
	{
		if(A[i] > 0)
		  sum_positive += A[i];
		else
		  sum_negative += A[i];
	}
	printf("\n\nSum of Positive Numbers :--> %d", sum_positive);
	printf("\nSum of Negative Numbers :--> %d", sum_negative);
	return 0;
}

Output:

Array Elements :--> 1  2  3  -1  -2  -3

Sum of Positive Numbers :--> 6
Sum of Negative Numbers :--> -6