Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 210

My factorial function is not returning factorial

$
0
0

I am not able to find out why my function returns the user input only rather then the factorial of the input.

#include <stdio.h>#include <math.h>int factorial(int x){    //int x;    int sum = 1;    while (x!=0){        sum = sum * x;        x--;    }    return sum;}int main(){    int x;    printf("Enter value of x: ");    scanf("%i",&x);    factorial(x);    printf("sum is %i", x);    return 0;}

Viewing all articles
Browse latest Browse all 210

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>