Wednesday, December 24, 2014

Program to Find Factorial of a Number Non-recursively

Posted By: BackBenchers World - Wednesday, December 24, 2014

Share

& Comment

#include<iostream.h>
#include<conio.h>

static double fact=1.0;       // Global Value

double factorial(int n)
{
  int i=1;

                     while(i<=n)
                     {
                                       fact=fact*i;
                                       i++;
                     }


                     return fact;
}

int main()
{
clrscr();

 int n;

 cout<<"Enter a number: ";

 cin>>n;

 cout<<"The factorial is: "<<factorial(n);

 getch();

 return 0;
 }

About BackBenchers World

Techism is an online Publication that complies Bizarre, Odd, Strange, Out of box facts about the stuff going around in the world which you may find hard to believe and understand. The Main Purpose of this site is to bring reality with a taste of entertainment

0 comments:

Post a Comment

Copyright © 2013 TechDotHunter™ is a registered trademark.

Designed by Templateism. Hosted on Blogger Platform.