C LAB‎ > ‎(Sem1) Introduction to C‎ > ‎

WAP to find the sum and average of 10 numbers using arrays.

posted Oct 30, 2010, 1:17 AM by Neil Mathew   [ updated Nov 6, 2010, 1:24 AM ]

SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
 
int main()
{
 
//INITIAL DECLARATIONS
int x[10]; 
int sum=0; 
float avg; 
int i;
 
 
//INPUT
printf("\n Enter the 10 numbers: \n ");
for(i=0; i<10; i++)
{
scanf(" %d ", &x[i]); // *Note the & for array element
}    //CALCULATIONS for(i=0; i<10; i++) { sum+=x[i]; } avg=sum/10.0;   //OUTPUT printf("\n The Sum of the numbers: %d ",sum); printf("\n The Average of the numbers: %f \n",avg);   return 0; }    

OUTPUT:


 Enter the 10 numbers: 
 1 2 3 4 5 6 7 8 9 10

 The Sum of the numbers: 55 
 The Average of the numbers: 5.500000 

Comments