what was the error

+9 votes
asked Sep 24 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);
}

15 Answers

0 votes
answered Sep 30 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 by Animesh Singh

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

0 votes
answered Oct 1 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 6 days ago by (190 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 2 days ago 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);
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.
...