Addition of Array elements
Write a program in C that accepts number of array elements from the user, accepts array element values and calculates the sum/addition of all the array elements. The program should display the value of addition.
#include<stdio.h> int main() { int arr[100], i, no,sum=0; clrscr(); printf("\nEnter the no. of elements: "); scanf("%d",&no); for(i=0;i<no;i++) { printf("\nEnter element %d",i+1); scanf("%d", &arr[i]); } for(i=0;i<no;i++) { sum=sum+arr[i]; } printf("\nsum of array element: %d",sum); return 0; }
Output:
Enter the no. of elements: 5 Enter element 1 : 1 Enter element 2 : 2 Enter element 3 : 3 Enter element 4 : 4 Enter element 5 : 5 Sum of Array element: 15
Good example!
nice very good example its helpful for me
Example needlessly abbreviates identifiers. Needlessly reduces readability.
sucess