C++ program to calculate the factorial of a number using recursion.

Write a program to calculate the factorial of a number using recursion.

#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);
	}
}
Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

20 thoughts on “C++ program to calculate the factorial of a number using recursion.

  1. #include
    #include

    using namespace std;

    int main(int argc, char *argv[])
    {
    int fact=1,num=1;
    cout <>num;
    if (num<=0);
    num=1;
    for(int count=1;count<=num;count++);
    { fact=*count
    ;
    cout <<fact;

    system("PAUSE");
    return EXIT_SUCCESS;
    }

  2. , the provided fuotcinn _might_ work as you expect, but it doesn’t _have_ to, so it’s just plain wrong. No sense talking about the efficiency of your code if there is such a major flaw in it -disclaimer-If you the code you gave here does not match up with the code you gave your interviewer, this whole rant makes no sense at all, but it should just match up. Honestly, though, it makes a whole lot of sense to me if that error was the reason you were shown the door, seeing that an inefficiency would not exactly constitute much of a reason to be _that_ convinced you aren’t qualified for the job

  3. #include
    #include
    #include
    long int fact(int);

    void main()
    {
    int n;
    long int f=1;
    clrscr();
    cout<>n;

    f=fact(n);
    cout<<"\n\nThe factorial of "<<n << " is "<<f;
    getch();

    }

    long int fact(int n)
    {
    long int f=1;

    if(n==1||n==0)
    return(1);
    else
    {
    f=n*fact(n-1);
    return(f);
    }

    }

  4. Thank you so much for providing individuals with an extraordinarily breathtaking possiblity to discover important secrets from this blog. It really is very terrific and stuffed with fun for me personally and my office peers to visit your web site minimum 3 times in 7 days to study the latest items you have. Of course, we are at all times fulfilled with all the striking secrets you serve. Selected 2 points on this page are completely the most impressive we have ever had. test2 http://testdomain.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in