Develop a C function to create an array with 10 float elements and create another
module which calculate the mean of float array.
Answers
#include <stdio.h>
int main()
{
int avg = 0;
int sum =0;
int x=0;
/* Array- declaration – length 3*/
int num[10];
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
avg = sum/10;
printf("Average of entered number is: %d", avg);
return 0;
}
sum = sum+num[x];
}
avg = sum/10;
printf("Average of entered number is: %d", avg);
return 0;
/}
_______________________________________
Enter number 1
10
Enter number 2
10
Enter number 3
10
Enter number 4
10
Enter number 5
10
Enter number 6
10
Enter number 7
10
Enter number 8
10
Enter number 9
10
Enter number 10
10
Average of entered number is: 10
Note :-
This coding is for 10 unit by changing units we can create n float elements with any of the value .
_______________________________________
Answer:
#include <stdio.h>
int main()
{
int avg = 0;
int sum =0;
int x=0;
/* Array- declaration – length 3*/
int num[10];
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
for (x=0; x<10;x++)
{
printf("10 %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<10;x++)
{
sum = sum+num[x];
}
avg = sum/10;
printf("Average of entered number is: %d", avg);
return 0;
}
sum = sum+num[x];
}
avg = sum/10;
printf("Average of entered number is: %d", avg);
return 0;
/}