b) Find the sum of positive numbers and
c) Find the average of all input numbers
Output the various results computed with proper headings */
#include <stdio.h>
#include <conio.h>
#define MAXSIZE 10
void main()
{
int array[MAXSIZE];
int i, N, negsum=0, posum=0;
float total=0.0, averg;
clrscr();
printf (“Enter the value of N\n”);
scanf(“%d”, &N);
printf(“Enter %d numbers (-ve, +ve and zero)\n”, N);
for(i=0; i< N ; i++)
{
scanf(“%d”,&array[i]);
fflush(stdin);
}
printf(“Input array elements\n”);
for(i=0; i< N ; i++)
{
printf(“%+3d\n”,array[i]);
}
/* Summing begins */
for(i=0; i< N ; i++)
{
if(array[i] < 0)
{
negsum = negsum + array[i];
}
else if(array[i] > 0)
{
posum = posum + array[i];
}
else if( array[i] == 0)
{
;
}
total = total + array[i] ;
}
averg = total / N;
printf(“\nSum of all negative numbers = %d\n”,negsum);
printf(“Sum of all positive numbers = %d\n”, posum);
printf(“\nAverage of all input numbers = %.2f\n”, averg);
} /*End of main()*/
/*————————————-
Output
Enter the value of N
5
Enter 5 numbers (-ve, +ve and zero)
5
-3
0
-7
6
Input array elements
+5
-3
+0
-7
+6
Sum of all negative numbers = -10
Sum of all positive numbers = 11
Average of all input numbers = 0.20
————————————–*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
- C program to find the number of integers divisible by 5 between the given range N1 and N2, where N1 < N2 and are integers. Also find the sum of all these integer numbers that divisible by 5 and output the computed results
- Write a C program to find the sum of ‘N’ natural numbers
- C program to find the GCD and LCM of two integers output the results along with the given integers. Use Euclids’ algorithm
- Sample – Program to find the sum of each row & column of a matrix of size n x m and if matrix is square, find the sum of the diagonals also..
