Goto Statement in C
Goto Statement in C
Syntax :
goto label;
goto.c
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter 2 nos A and B one by one : ");
scanf("%d%d",&a,&b);
if(a>b)
{
goto first;
}
else
{
goto second;
}
first:
printf("\n A is greater..");
goto g;
second:
printf("\n B is greater..");
g:
getch();
}
Output :
#include <stdio.h>
int main()
{
int c, n, fact = 1;
Output of code:
long factorial(int);
int main()
{
int number;
long fact = 1;
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
return result;
}
long factorial(int);
int main()
{
int n;
long f;
if (n < 0)
printf("Negative integers are not allowed.\n");
else
{
f = factorial(n);
printf("%d! = %ld\n", n, f);
}
return 0;
}
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
Recursion is a technique in which a function calls itself, for example in above code factorial
function is calling itself. To solve a problem using recursion you must first express its solution in
recursive form.