A program to calculate summation and average of array elements

 Summation and Average of Array



            In this example, we will  understand to perform  summation and average of array elements and know how to write, compile and debug it in C language and also learn how to implement it in c.

        
In order to do this you will need
  • Basic knowledge of c programming language.
  • As well as know how to operate codeblocks.   

            An array is a fixed-size sequential collection of  elements of same data types that share a common  name.It is simply a group of data types. An array is a  derived data type.An array is used to represent a list of numbers or  a list of names.


So let's begin with our program

1.Open a codeblocks software.

2.Open new empty file.

3.Copy and paste the code from below. 






Input code-

 //Write a program to calculate sum and average of array elements  
   
 #include<stdio.h>  
 int main()  
 {  
    int array[5],n,i,sum=0,avg;  
    printf("enter the numbers you want to insert less than 100: ",&n);  
    scanf("%d",&n);  
     for(i=0;i<4;i++)  
     {  
       printf("\nenter the element %d: ",i+1);  
       scanf("%d",&array[i]);  
       sum=sum+array[i];  
     }  
       avg=sum/n;  
     printf("\nthe sum of array is=%d",sum);
     printf("\nthe avg of array is=%d",avg);  
   
   return 0;  
 }  
   



Now simply build the code. Look for any error. Now run the code.

For output enter any number which is less than 100 now enter any 4 element you want and press enter key.



A program to calculate summation and average of array elements,c programming language,2021,basic codes,input output code



Click the following button to download a program to calculate factorial using function.





Thats it.Thank you for scrolling.



Post a Comment

If you have any doubt or suggestions.please let me know.

Previous Post Next Post

Ads by google

Ads by google