program to find product of first n natural numbers.
#include <iostream.h>
int main()
{
int n;
int i=1,prod=1;
cout<<“enter range:”;
cin>>n;
while(i<=n)
{
prod=i*prod;
i++;
}
cout<<“sum is:”<<prod;
return 0;
}
int main()
{
int n;
int i=1,prod=1;
cout<<“enter range:”;
cin>>n;
while(i<=n)
{
prod=i*prod;
i++;
}
cout<<“sum is:”<<prod;
return 0;
}
No comments:
Post a Comment