Posts

Showing posts from March, 2022

C Program to Calculate Sum & Average of an Array

                          This is a C Program to calculate the sum & average of an array. Problem Description We have to write a program in C such that we are reading an array of N elements and then we are going to calculate the sum and average of those N elements and display it to the standard output or screen. Expected Input and Output If we are entering 5 elements (N = 5), with array element values as 10, 20, 30, 40 and 50 then, 1.  Sum of Elements of the array will be : 10 + 20 + 30 + 40 + 50 = 150 2.  Average of Elements of the array will be : 150 / 5 = 30  Problem Solution Fundamentally, an array is a data structure containing a collection of values or variables. The simplest type of array is a linear array or one-dimensional array. An array can be defined in C with the following syntax: int Arr[5] = {10, 20, 30, 40, 50}; /* here 10,20,30,40,50 are the elements at indices 0,1,2,3,4 respectively */ In this example, array  Arr  is a collection of 5 integers. Each integer can be