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:
No comments:
Post a Comment