Factorial by goto statement in C by R4R Team

Factorial:

-factorial of number is the multiplication of every integer number between 1 and that number.

Example-
factorial of 3 is 6(1*2*3)
factorial of 5 is 120(1*2*3*4*5)

Goto:

-This statement are used to jump from one line to another line in the program.
-It is the jumping statement in C.

Syntax-
xyz:
goto xyx;

-when the execution of program are come at the goto line then it will jump to the xyz: line.
-Goto statement are also be used to make a loops.
-Goto statement are also goes in infinite loop.


program-

#include < stdio.h>
int main()
{
int n,fac=1;
printf("Enter Any Number\n");
scanf("%d",&n);
point:
fac=fac*n;
n=n-1;
if(n>0)
goto point;
printf("Factorial is %d",fac);
}


output-

Enter Any Number
5
Factorial is 120

Enter Any Number
6
Factorial is 720

-In this program, we create a loop type structure with the goto statement that are able to find the factorial of the input number.




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!