C Factorial program

Why is this error giving…:thinking:

#include <stdio.h>
int fact(int);
int main(void) {
    int n,f;
    printf("Enter number to find factorial ");
    scanf("%d", &n);
    f = fact(n);
    printf("%d", f);
    return 0;
}

int fact(int n){
    n > 1 ? n * fact(n - 1) : 1;
    return n;
}

check here
c program to find factorial

If you meant to ask why it doesn’t seem to work, that’s because the ternary isn’t actually used at all—the return statement simply returns the value of the argument that was passed in. The function should look like this for the program to work:

int fact(int n) {
    return n > 1 ? n * fact(n - 1) : 1;
}

Also, there’s always a time & place to use a ternary. This isn’t exactly one of them, as it decreases the readability of the code.

but this program work in JavaScript successfully

const factorial = n => n > 1 ? n * factorial(n - 1) : 1;

factorial(5);

but this program work in JavaScript successfully

const factorial = n => n > 1 ? n * factorial(n - 1) : 1;

factorial(5);

That’s because of in JS in arrow function (which you used as an example) return substitutes automatically.
So basically it’s equal to this in C:

int fact(int n){
   return  n > 1 ? n * fact(n - 1) : 1;
}

You could find more about arrow functions here

Or in terms for ES5 (JS):

var num = 10 // input number (poteinal parameter for function)
var fact = nun
for (var i = 1; i < num; i++) {
fact *= i 
}
return fact