what was the error

+12 votes
asked Sep 24, 2019 by (260 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 (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 (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 2 days ago by anonymous
semi colon beside declaration. int fact(int)";"
0 votes
answered 1 day ago by (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.
...