Skip to main content

Posts

Showing posts from April 24, 2021

Calculate the sum of elements in an array.

  HOW TO CALCULATE THE SUM OF THE ELEMENT IN A GIVEN ARRAY: - We will learn how to find the sum of elements in an array is an easy task when you know how to iterate through array elements. In this problem, we will explain your C approach to find the sum of array elements inputted by the user. Here is the solution to this query in C Languageguage.   ALGORITHMS: STEP 1:-   Input the size of the array and store the value in m and arr[m]. STEP 2 : - To store the sum of array elements, initialize a variable sum = 0. STEP 3: -To find the sum of all elements, iterate through each element  and add the current element to the sum. STEP 4: - Inside the loop add the current array element to sum i.e.                 sum = sum + arr[i] or sum += arr[i]. CODE:- #include <stdio.h> int  main() {      int  i,num,a[ 100 ],sum= 0 ;     printf( "Enter the value of number: " );     scanf( "%d" ,&num);     printf( "Enter value of array: " );      for (i= 0 ;i<num;i