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
Post a Comment