Tuesday 16 May 2017

Printing all factorials in a given range in c++


#include<iostream>
using namespace std;
void factorial(int start,int end);          //prototype of function
int main(){
int start,end;
cout<<" enter the starting value of factorials "<<endl;
cin>>start;
cout<<"enter the ending value of factorials "<<endl;
cin>>end;
cout<<" now will print the all factorials "<<endl;
factorial(start,end);
}
void factorial(int start,int end){

while(start!=end){  //program will run until start is not equal to end
int a=1;
for(int x=1;x<=start;x++){ // program will run from 1 to start
a=a*x;
}
cout<<start<<" = "<<a<<endl;
start++;   //start is incremented by 1
}
}



1 comment: