A program that calculates factorial of a number input by user

// Stacklink.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;



int _tmain(int argc, _TCHAR* argv[])

{
                   int num, fact = 1, index;
            cout<<"Input value for which factorial is required ";
            cin>>num;
            index = num;
                  cout<<endl;
           cout<<num<<"! = ";
            while (index > 0)
            {


                if (index == 1)
                    cout<<index<<endl;
                else
                   cout<<index<<" * ";

                fact *= index;
                index--;

            }

            cout<<"\nFactorial of "<<num<<" is "<<fact<<endl;
}


Comments

Popular posts from this blog

Check if ViewBag is null or doesn't exist

Using Progress Bar In C#

Jquery serer side datatables in asp.net