Monday, May 5, 2008

program to find factorial in C++ upto a given term

Write a program that will take a number N as input and print the factorial of all numbers from 1 to N

PROGRAM:

#include <iostream.h>

#include <conio.h>

void main() {

clrscr();

long int fact;

int num, temp;

cout<<"Enter the number upto which you wan to generate factorial: ";

cin>>num;

cout<<”Program Factorial: “;

for(int i=1;i<=num;i++) {

temp=i;

fact=1;

while(temp>0) {

fact*=temp;

temp--;

}

cout<<"\n"<<i<<" ! = "<<fact;

}//end of for loop

getch();

}//end of the program

No comments: