Write a program to find the sum of all elements of the array

Write a program to find the sum of all elements of the array.

  1. #include <stdio.h>

  2. void main()
  3. {
  4.     int arr[100];
  5.     int i, n;
  6.     int sum=0;
  7.     printf("Enter the number of elements to be stored in the array : ");
  8.     scanf("%d", &n);

  9.     printf("Enter %d elements in the array :\n", n);
  10.     for(i=0; i<n; i++) {
  11.           printf("Element - %d : ", i);
  12.           scanf("%d", &arr[i]);
  13.         }
  14.         
  15.     for(i=0; i<n; i++) {
  16.         sum = sum + arr[i];
  17.     }
  18.     
  19.     printf("Sum of all elements of array = %d", sum);
  20. }

একটি মন্তব্য পোস্ট করুন