Answer to Question #25206 in C# for Malik

Question #25206
Develop a serial program to calculate a factorial using a for loop. No recursion. Time it.

to be done in c language.
1
Expert's answer
2013-02-27T04:20:55-0500
#include <iostream>
using namespace std;
void main()
{
int enteredNumber;
long result = 1;
printf("%s","enter the number from 1 to 16\n");
/*entered number can not exceed 16,
otherwise the program will give the wrong result,
because the results size will exceed of the 8 bytes*/
scanf("%d",&enteredNumber);
if(enteredNumber > 16)
{
printf("%s","entered number can not exceed 16,otherwise the program will give the wrong result,because the results size will exceed of the 8 bytes\n");
return;
}
for( int i = 1; i<=enteredNumber; i++ )
{
if(enteredNumber == 1)break;
result *= i;
}
printf("%d",result);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS