write a program to find the factorial of no. between (2-7) by nested if loops do if you think you should have a place in leaderboard a challenge for all brainly users....by Miss Riya Arora
Answers
Hello !
here's your answer
#include<stdio.h>
main()
{
int fact=1, n, i, j;
printf("Enter the number whose factorial is to be found \n");
scanf("%d",&n);
if(n>=1)
{
fact=fact*n;
n--;
if(n>=1)
{
fact=fact*n;
n--;
if(n>=1)
{
fact=fact*n;
n--;
if(n>=1)
{
fact=fact*n;
n--;
if(n>=1)
{
fact=fact*n;
n--;
if(n>=1)
{
fact=fact*n;
n--;
if(n>=1)
{
fact=fact*n;
n--;
if(n>=1)
{
fact=fact*n;
n--;
}}}}}}}}
printf("The factorial of the given number is %d",fact);
}
NOTE : According to the question since it was asked for a specific case i.e. to find factorial between 2-7 this program will work fine for 2-7 only.
The same question can be solved by loops to with nested if :- (I'll mention that logic also )
Main logic :-
for(i=7; i>=1; i--)
{
if(n>=1)
{
fact=fact*n;
n--;
if(n>=1)
{
fact=fact*n;
n--;
}}
}
Hope it helps ! ^_^