Product all number in Array by R4R Team

Example-
array is {4,5,3,2,1}
prodcut of all elements are 120

program-

#include< stdio.h>
int main()
{
int a[100],n,i,ans=1;
printf("Number of element in array ?\n");
scanf("%d",&n);
printf("Enter %d number in array\n",n);
for(i=0;i< n;i++)
scanf("%d",&a[i]);
//Now calculate the product
for(i=0;i< n;i++)
ans=ans*a[i];
printf("Product of all number in array is %d",ans);
}


output-

Number of element in array ?
4
Enter 4 number in array
1 2 3 4
Product of all number in array is 24

-In this program, we take a input in the array and try to multiple all elements of array.
-We run loop and multiple each elements of array to variable 'ans'




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!