[Solved] Sum and get the average of the values in the array


Answer of your Question

#include  <stdio.h>
     int main()
 {
int array[10];
int num, negative_sum = 0, positive_sum = 0,j;
static int i=0;
float total = 0.0, average;
label:
j=i;
printf ("Enter the value of N \n");
scanf("%d", &num);
printf("Enter %d numbers (negative, positve and zero) \n", num);
for (i; i < (j+num); i++)
{
scanf("%d", &array[i]);
}
i=j;
printf("Input array elements \n");
for (i; i < (j+num); i++)
{
printf("%d\n", array[i]);
}
i=j;
for (i; i < (j+num); i++)
{
if (array[i] < 0)
{
    negative_sum = negative_sum + array[i];
}
else if (array[i] > 0)
{
    positive_sum = positive_sum + array[i];
}
else if (array[i] == 0)
{
    ;
}
total = total + (float)array[i] ;
}
average = total / num;
printf("\n Sum of all negative numbers =  %d\n", negative_sum);
printf("Sum of all positive numbers =  %d\n", positive_sum);
printf("\n Average of all input numbers =  %.2f\n", average);
if(total<10000)
{
printf("Total is less than 10000 and Now total is : %.2f\n",total);
 goto label;
}}

it is the answer of your question.program will run when your total is exceed upto 10000.

0

solved Sum and get the average of the values in the array