20_10

Write a C program to calculate Sum and Product of all Elements in an array.

Source code:

 //C program to calculate Sum and Product of all Elements in an array

#include <stdio.h>

int main() 

    int arr[10]; 

    int sum,product,i;

    /*Read array elements*/

    for(i=0; i<10; i++) 

    {  

    printf("Enter the value for %d: ",i);

        scanf("%d",&arr[i]); 

    }

sum=0;

product=1;

for(i=0;i<10;i++)

{

sum+=arr[i];

    product*=arr[i];

}

printf("Sum of array is:%d\n",sum); 

printf("Product of array is:%d",product);

return 0;

}

Output:
C program to calculate Sum and Product of all Elements in an array


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...