these are 2 programs that I need to depend on recursive functions when writing them but they give me wrong answers.Plz help
Code:
This program is for calculating the factorial of a number the user inputs:
#include<stdio.h>
#include<math.h>
int main(void)
{
int n;
int factorial(int n);
int y;
y=factorial(n);
printf("enter the number you wish to calculate its factorial:");
scanf("%d" ,&n);
printf("the answer is:%d" ,y);
}
int factorial(int n){
if(n==0)
return (1);
else
return (n*factorial(n-1));
}
Code:
This program is for calculating numbers raised to integer powers.
#include<stdio.h>
#include<math.h>
int main(void)
{
int x,y;
int power(int x, int y);
int d;
d=power(x,y);
printf("enter the number of the base then the number of the power:");
scanf("%d%d" ,&x, &y);
printf("the answer is:%d" ,d);
}
int power(x,y){
if(y==0)
return (1);
else
return (x*power(x,(y-1)));
}