I have to do a program that calculates the factorial of a number using recursion inside the main.
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main (int argc, char *argv[]){
float numero;
int valorA = atoi(argv[1]);
char var1[10];
itoa(valorA-1, var1, 10);
if (valorA <= 1)
return(1);
else{
numero = valorA * main(argc, var1);
return numero;
}
printf("Fatorial de %d = %.2f", atoi(argv[1]), numero);
}
When I pass the number as an argument at the command prompt an error occurs, saying that the program has stopped working. What is the problem with my code?