0% found this document useful (0 votes)
24 views

ASSIGNMENT NO CMSG (Jaipuria) .CPP

The document describes a C program to calculate the factorial of a given number. It takes the number N as input from the user, initializes a variable fact to 1, and uses a for loop to multiply fact by each integer from 1 to N. It then prints the factorial of N. The source code provided implements this algorithm by prompting the user for input, storing it in n, initializing fact to 1, using a for loop to update fact as fact = fact * c for each c from 1 to n, and finally printing the result. Sample output for inputs 5, 6, and 10 are included.

Uploaded by

Lukas Bright
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

ASSIGNMENT NO CMSG (Jaipuria) .CPP

The document describes a C program to calculate the factorial of a given number. It takes the number N as input from the user, initializes a variable fact to 1, and uses a for loop to multiply fact by each integer from 1 to N. It then prints the factorial of N. The source code provided implements this algorithm by prompting the user for input, storing it in n, initializing fact to 1, using a for loop to update fact as fact = fact * c for each c from 1 to n, and finally printing the result. Sample output for inputs 5, 6, and 10 are included.

Uploaded by

Lukas Bright
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT NO:

Problem Statement:
To write a program in C to calculate the factorial of a given
number,where Nis the input given by the user.

Algorithm:
Variable listing:
Name Data type Function
C Int Assigned 1 so the value
is not less than N.
N Int it is the input given by
the user.
Fact Int A factorial is a product
of all the numbers
starting from 1.

Step 1: Enter the value of “n”.

Step 2: Read “N”.

Step 3: Set fact=1.

Step 4: for( c=1;c<=n;c++) then

Step 5: i) fact =fact*c.

ii) printf(“factorial of %d=%d\n”,n,fact).

Step 6: return 0.

Step 7: stop.
Source Code :
#include<stdio.h>
int main()
{
int c,n,fact=1;
printf("enter a number to calculate its factorial\n");
scanf("%d",&n);
for(c=1;c<=n;c++)
fact=fact*c;
printf("factorial of%d=%d\n",n,fact);
return 0;
}
<OUTPUT>

Set 1:
Enter a number to calculate its factorial
5
Factorial of 5=120

Set 2:
Enter a number to calculate its factorial
6
Factorial of 6=720

Set 3:
Enter a number to calculate its factorial
10
Factorial of 10=3628800

-:-------------------:-

You might also like