write a program that finds the factorial of a number using
recursion?

Answer Posted / prasenjit banik

#include<iostream.h>
#include<conio.h>
void main()
{
int n,fact;
int rec(int); clrscr();
cout<<"Enter the number:->";
cin>>n;
fact=rec(n);
cout<<endl<<"Factorial Result are:: "<<fact<<endl;
getch();
}
rec(int x)
{
int f;
if(x==1)
return(x);
else
{
f=x*rec(x-1);
return(f);
}
}

Is This Answer Correct ?    14 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Read the following data in two different files File A: aaaaaaaadddddddd bbbbbbbbeeeeeeee ccccccccffffffff File B: 11111111 22222222 33333333 By using the above files print the following output or write it in the Other file as follows aaaaaaaa11111111dddddddd bbbbbbbb22222222eeeeeeee cccccccc33333333ffffffffffff

2234


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1487


How can I check whether a file exists? I want to warn the user if a requested input file is missing.

651


Is c easy to learn?

552


What is 'bus error'?

637






What is infinite loop?

622


How do you sort filenames in a directory?

700


How can I get back to the interactive keyboard if stdin is redirected?

663


Why flag is used in c?

650


Explain what is the benefit of using enum to declare a constant?

581


What type of function is main ()?

580


What are the advantage of c language?

545


Define VARIABLE?

684


How can I delete a file?

625


What is the use of void pointer and null pointer in c language?

621