Programming for Problem Solving

GTU Practical 47

47. Write a C program using a global variable and static variable.
#include<stdio.h>  ( this applies in the given code )

#include

int fact();
int n;
int main()
{
printf(“\n Enter Value of n :”);
scanf(“%d”,&n);
printf(“Factorial = %d”,fact());
return 0;
}

int fact()
{
static int ans=1;
if(n==1)
{
return ans;
}
ans = n– * fact();
}

OUTPUT

Enter Value of n :15.22
Factorial = 2004310016

GTU STUDY