Automata Question – 5
Q5. Find the factorial of a given number.
int main()
{
long int fact = 1, n, i;
scanf(“%d”, &n);
for(i =1; i <= n; i++)
{
fact = fact * i;
}
printf(“%d”, fact);
return 0;
}2) Find the factorial of a given number.
int main()
{
long int fact = 1, n, i;
scanf(“%d”, &n);
for(i =1; i <= n; i++)
{
fact = fact * i;
}
printf(“%d”, fact);
return 0;
}
Input: 20
Output: -2102132736
Answer: Error – Logical error
The fact and n are declared as long int, so in scanf and printf %ld should be used in
place of %d.
- Number of Questions – 2 Questions
- Difficulty Level – ★★★
- Average time to solve – 30 sec
Login/Signup to comment