C++ program of Factorial

C, C++, etc Programing examples. Post as many you can. Test the programs and discuss about the output of the programes.
Forum rules
Please Discuss & post only about the programes and its Output

C++ program of Factorial

Postby Piya » Wed Apr 22, 2009 10:12 am

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

void main()
{
int j,no;
int factorial(int); //initinalize the function
// cout<<" --<<ENTER THE NUMBER>>--";
// cin>>no;
for(j=0;j<no;j++)
cout<<"\n"<<"THE FACTORIAL OF:-"<<j<<"="<<factorial(j);
}
factorial(j)

{
int n;
n=j;
int fact;
if(n==0)
return 1;
else
{
fact=n*factorial(n-1); //the last factorial is multiple with the number
return fact; //return value.
}

}
User avatar
Piya
Super Member
Super Member
 
Posts: 9
Joined: Thu Apr 16, 2009 3:46 pm
membership: Senior Technician of The Institution of Engineers (India)- ST

ad
 

Re: C++ program of Factorial

Postby praveen » Wed Apr 22, 2009 12:46 pm

Thanks for the program..
Regards,
Praveen
AMIE Study

ImageImage
-------------------------------------------------------------------------------------------
Work from Home | AMIE Online Coaching
User avatar
praveen
Site Admin
 
Posts: 989
Joined: Thu Oct 23, 2008 1:42 pm
Location: Mumbai
membership: Senior Technician of The Institution of Engineers (India)- ST

Re: C++ program of Factorial

Postby irfanmasiullah » Tue Apr 13, 2010 6:05 am

Hello.

I have one doubt...
I study c++ by video and compiled also on Dec c++ compiler.
# include <iostream> /* THIS IS I learned by video and complier accept this*/
but I saw in your program #include <iostream.h>

Please clearify....
Thanks
Thanks & Best Regards -
Irfan M Ansari - Section B - Civil
MOB- 00966 561 770 321 - Dammam - Saudi Arabia
Email :irfanmasiullah@gmail.com
IM: irfanmasiullah@yahoo.com : irfanmasiullah@gmail.com
User avatar
irfanmasiullah
Super Member
Super Member
 
Posts: 77
Joined: Thu Jul 30, 2009 7:59 pm
Location: Mumbai / Dammam (Saudi Arabia)
membership: Senior Technician of The Institution of Engineers (India)- ST

Re: C++ program of Factorial

Postby charulatha » Tue Apr 13, 2010 2:41 pm

as far as i studied #include <iostream.h> is correct. u have to add .h (header).
Regards,
Charulatha.
User avatar
charulatha
Moderator
 
Posts: 669
Joined: Sat Oct 17, 2009 2:54 pm
membership: Senior Technician of The Institution of Engineers (India)- ST

Re: C++ program of Factorial

Postby irfanmasiullah » Wed Apr 14, 2010 12:36 pm

Hello.
I c its require, like #include <stdio.h>

when I compiled putting .h also then compiler says its wrong.
If you give me your email address, I will send come video tutorial also.

Regards
Irfan
irfanmasiullah@gmail.com
Thanks & Best Regards -
Irfan M Ansari - Section B - Civil
MOB- 00966 561 770 321 - Dammam - Saudi Arabia
Email :irfanmasiullah@gmail.com
IM: irfanmasiullah@yahoo.com : irfanmasiullah@gmail.com
User avatar
irfanmasiullah
Super Member
Super Member
 
Posts: 77
Joined: Thu Jul 30, 2009 7:59 pm
Location: Mumbai / Dammam (Saudi Arabia)
membership: Senior Technician of The Institution of Engineers (India)- ST

Re: C++ program of Factorial

Postby rohit.wadhwa » Fri Apr 16, 2010 6:11 pm

Hello C++ fans,

I have observed that when using #include<iostream.h> , using namespace std; is not required.
(Namespaces are used to avoid multiple symbol definitions when using several libraries.you already know.)
Code: Select all
<iostream>
is the standard header
Code: Select all
<iostream.h>
is the old standard header, not longer supported by some compilers

but remember you can't write conio in place of 'conio.h' like iostream.
A frequent piece of advice is often given to new C++ programmers is to use <iostream> instead of <iostream.h> or <fstream> instead of <fstream.h> [according to you compiler version]

Here is a link I found that gives some background on why there are two versions of iostream headers. You could probably find a lot of articles on the subject using a search engine. I searched on "iostream vs. iostream.h".
http://members.gamedev.net/sicrane/articles/iostream.html
hope its clear you doubt.
Thanks
Rohit Wadhwa
Site : Study Site
User avatar
rohit.wadhwa
Moderator
 
Posts: 55
Joined: Mon Mar 16, 2009 4:00 pm
Location: Hisar(Haryana)
membership: Senior Technician of The Institution of Engineers (India)- ST

Re: C++ program of Factorial

Postby irfanmasiullah » Sat Apr 17, 2010 12:19 pm

Thank you Mr. Rohit.
You are always helpfull.
Thanks & Best Regards -
Irfan M Ansari - Section B - Civil
MOB- 00966 561 770 321 - Dammam - Saudi Arabia
Email :irfanmasiullah@gmail.com
IM: irfanmasiullah@yahoo.com : irfanmasiullah@gmail.com
User avatar
irfanmasiullah
Super Member
Super Member
 
Posts: 77
Joined: Thu Jul 30, 2009 7:59 pm
Location: Mumbai / Dammam (Saudi Arabia)
membership: Senior Technician of The Institution of Engineers (India)- ST

Re: C++ program of Factorial

Postby ram1ramji » Wed Mar 23, 2011 5:30 pm

Thank you...Useful discussion...

Regards
Ramji
Regards
Ramji R
ram1ramji
Registered User
 
Posts: 20
Joined: Mon Sep 27, 2010 6:02 pm
membership: NA


Return to Computer Notes : Some Sample Programs

Who is online

Users browsing this forum: snehalkshirsagar and 0 guests