Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what was the error

+17 votes
asked Sep 24, 2019 by Gopi Jonnalagadda (250 points)
#include <stdio.h>
int fact(int )
int main()
{
    int x;
    printf("enter the number x");
    scanf("%d",&x);
    int res=fact(x);
    printf("the factorial of %d is%d",x,res);
    return(0);
    

}
int fact(int n)
{
    if(n==1)
    return 1;
    else
    return n*f(n-1);
}

19 Answers

0 votes
answered Sep 30, 2019 by anonymous
#include <stdio.h>
int fact(int );
int main()
{
    int x;
    printf("enter the number x");
    scanf("%d",&x);
    int res=fact(x);
    printf("the factorial of %d is%d",x,res);
    return(0);
    }
int fact(int n)
{
    if(n==1)
    return 1;
    else
    return n*fact(n-1);
}
0 votes
answered Sep 30, 2019 by Animesh Singh

it should be return n*fact(n-1)

0 votes
answered Oct 1, 2019 by Anonymous
#include <stdio.h>

int fact(int n)
{
    if(n==1)
    return 1;
    else
    return n*fact(n-1);
}

int main()
{
    int x;
    printf("enter the number x");
    scanf("%d",&x);
    int res=fact(x);
    printf("the factorial of %d is%d",x,res);
    fact(x);
    
}
0 votes
answered Oct 8, 2019 by bhupath (210 points)
-f instead of fact

-remove the second line

Please find the below corrections:

#include <stdio.h>
int main()
{
    int x;
    printf("enter the number x");
    scanf("%d",&x);
    int res=fact(x);
    printf("the factorial of %d is%d",x,res);
    return(0);
    

}
int fact(int n)
{
    if(n==1)
    {
    return 1;
    }
    else{
    return n*fact(n-1);
    }
}
0 votes
answered Oct 12, 2019 by anonymous

Errores:

 int main()
main.cpp: In function ‘int fact(int)’:
main.cpp:30:19: error: ‘f’ was not declared in this scope
     return n*f(n-1);
0 votes
answered Dec 22, 2019 by kotha kushal (560 points)

#include <stdio.h>
int fact(int);
int main()
{
    int x;
    printf("enter the number x");
    scanf("%d",&x);
     int res=fact(x);
    printf("the factorial of %d is %d",x,res);
    return(0);
}
int fact(int n)
{
    if(n==1)
    return 1;
    else
    return n*fact(n-1);
}

0 votes
answered Dec 23, 2019 by anonymous

#include <stdio.h>
int fact(int );
int main()
{
    int x;
    printf("enter the number x");
    scanf("%d",&x);
    int res=fact(x);
    printf("the factorial of %d is%d",x,res);
    return(0);
    

}
int fact(int n)
{
    if(n==1)
    return 1;
    else
    return n*fact(n-1);
}

0 votes
answered Feb 16, 2020 by anonymous
semi colon beside declaration. int fact(int)";"
0 votes
answered Feb 17, 2020 by Umar Ali (140 points)
missing ; after function protocol declaration and wrong function call f(n-1) when it should be fact(n-1)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...