473,378 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

need help for project

uhm i have a question

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. clrscr();
  3.            long factorial(long);
  4.            void main(void) {
  5.                                   long number;
  6.                                   cout<<"Please enter a positive integer ";
  7.                                   cin>>number;
  8.            if(number<0)
  9.                                   cout<<"That is not a positive integer.\n ";
  10.            else
  11.                                   cout<<number<<"factorial is: "<<factorial(number)<<endl;
  12. }
  13.            long factorial(long number) {
  14.            long temp;
  15.            if(number<=1) return 1;
  16.                                   temp=number * factorial(number -1)
  17.            return temp;
  18. }

the problem is i cant think of a way that i can print the output of this program
-after i entered 17
the factorial is in negative sign.

is it possible to run it and enter any digits above 100??

can you help me...pls....tnx
Jan 19 '08 #1
2 1077
Ganon11
3,652 Expert 2GB
The problem is that 17! is a massive number - an int, or even a long int, cannot old that large a number. In order to compute large factorials, you need to mess around with classes or use some built in classes/functions. There are several threads going around with users asking the same question - see if they have found any help that you can use.

As an aside, you should never ever use void main(). It is a nonstandard practice that will not work in, say, my compiler, or my neighbor's compiler, or my professor's compiler, etc. It only works in a select few compilers, because it is flat out wrong. Instead, use int main() and return 0; at the end of your main function. Voila! Now your code works everywhere.
Jan 19 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
Also, iostream.h is an obsolete C++ header file. It is the non-ANSI C++ from prior to 1998.

You should be using:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
Jan 20 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Mark | last post by:
Hi, For the last 2 years I've been developing vehicle tracking/telemetric software for a company as a self employed individual. The project is quiet big, and is going to be there flagship...
3
by: Andrej Hristoliubov | last post by:
I am the best c++ programmer in the whole wide world. Trust ME! My reference is Victor Bazarov,Valentin Samko,Alf P.Steinbach( Me and Alf actually intern together at Microsoft), and Bjarne...
10
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
6
by: sivashankar | last post by:
hello experts -can any one give me some module to do in asp.net -if u give me the description i will give u with free of cost,since am new now am in my final semester of MCA,just give me some...
7
by: moondaddy | last post by:
I want to create a public enum that can be used throughout a project. I created an enum like this in a module: Public Enum ParentType Project = 0 Stage = 1 VIP = 2 Func = 3 Equipment = 4...
5
by: info | last post by:
Hi! Please be patient with a newbie... I use DevC++. I've found and compiled succefully various openGL examples. Before build the application, I link the project with static libs, like, in...
8
by: Brett Romero | last post by:
I have this situation: myEXE <needs< DerivedClass <which needs< BaseClass Meaning, myEXE is using a type defined in DerivedClass, which inherits from BaseClass. I include a reference to...
0
by: garimaarora | last post by:
hi i am a beginner of c++ language and had tried to build a project in c++ language the project is throwing me set of exceptions and i need ur help if there is anybody who is interested in...
10
by: Frank | last post by:
I've done this a few times. In a solution I have a project, Say P1, and need another project that will contain much code that is similar to that of P1. I hope no one gets hung up on why I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.