Hi there. I am making a program that asks a user to input 10 elements of an array and then displays the sum of the elements along with the average and how much each element is as a percent of the total.
My main issue is that I cannot get my mean and how much each element accounts for as a percent of the total. Here is a sample output followed by my code.
enter the elements
10
9
8
7
6
5
4
3
2
1
n percent of total
___________________
10 %d
9 %d
8 %d
7 %d
6 %d
5 %d
4 %d
3 %d
2 %d
1 %d
The total value of the array is 55
The mean value of the array is 0
Code:
#include <stdio.h>
#include <stdlib.h>
#define THE_LENGTH 10
void main()
{
int a[THE_LENGTH],i,sum = 0;
double mean = 0;
printf("enter the elements\n");
for(i=0;i<THE_LENGTH;i++)
scanf("%d",&a[i]);
for(i=0;i<THE_LENGTH;i++)
{
sum += a[i];
}
printf("n percent of total\n");
printf("___________________\n");
for(i=0;i<THE_LENGTH;i++)
{
printf("%d %%d\n", a[i], a[i]/sum);
}
printf("The total value of the array is %d\n",sum);
printf("The mean value of the array is %d\n", sum/10.0);
}