Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

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

 // Write a program in C to find the sum of all elements of the array


#include<stdio.h>

    int main(){

    int a[100],n,i,sum=0;

    printf("enter the number of elements\n");
    scanf("%d",&n);

    for (i = 0 ; i < n ; i++ )
    {
        printf("enter the number : ");
        scanf("%d",&a[i]);
    }

    for ( i = 0 ; i < n ; i ++ )
    {
        sum = sum + a[i];
    }

    printf("sum = %d",sum);

    return 0;

Post a Comment

0 Comments