| | |
Factorial?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2003
Posts: 7
Reputation:
Solved Threads: 0
can anyone come up with a solution for this ? real quick for me?
the factorial of a nonnegative integer n is written n! ("n factorial") and is defined as follows: n!=n*(n-1)*(n-2)*.....*1(for values of n greater than to 1)
and n!=1 (for n=0 or n=1).
For example, 5!=5*4*3*2*1, which is 120. Use a while structure for the following..write a program that reads a nonnegative integer and computes and prints its factorial.
If anyone could this for me thanks.
the factorial of a nonnegative integer n is written n! ("n factorial") and is defined as follows: n!=n*(n-1)*(n-2)*.....*1(for values of n greater than to 1)
and n!=1 (for n=0 or n=1).
For example, 5!=5*4*3*2*1, which is 120. Use a while structure for the following..write a program that reads a nonnegative integer and computes and prints its factorial.
If anyone could this for me thanks.
0
#2 Feb 23rd, 2003
C++ Syntax (Toggle Plain Text)
int x, factorial = 1; cout << "Enter integer: "; cin >> x; if (x > 0) { while (x > 0) { factorial *= x; x--; } } cout << "Factorial: " << factorial;
Untested, this might work.
1
#5 Feb 23rd, 2003
Oops! Just realized
the last line should cout << factorial
not cout << x
edited post above to fix error
the last line should cout << factorial
not cout << x
edited post above to fix error
•
•
Join Date: Feb 2003
Posts: 7
Reputation:
Solved Threads: 0
0
#6 Feb 23rd, 2003
Compiling...
3.cpp
C:\c++ storage\3.cpp(7) : error C2143: syntax error : missing ';' before '<<'
C:\c++ storage\3.cpp(7) : error C2501: 'cout' : missing storage-class or type specifiers
C:\c++ storage\3.cpp(7) : error C2143: syntax error : missing ';' before '<<'
C:\c++ storage\3.cpp(9) : error C2143: syntax error : missing ';' before '>>'
C:\c++ storage\3.cpp(9) : error C2501: 'cin' : missing storage-class or type specifiers
C:\c++ storage\3.cpp(9) : error C2143: syntax error : missing ';' before '>>'
C:\c++ storage\3.cpp(12) : error C2143: syntax error : missing ';' before 'if'
C:\c++ storage\3.cpp(13) : error C2143: syntax error : missing ';' before '{'
C:\c++ storage\3.cpp(13) : error C2447: missing function header (old-style formal list?)
C:\c++ storage\3.cpp(20) : error C2143: syntax error : missing ';' before '<<'
C:\c++ storage\3.cpp(20) : error C2501: 'cout' : missing storage-class or type specifiers
C:\c++ storage\3.cpp(20) : error C2086: 'cout' : redefinition
C:\c++ storage\3.cpp(20) : error C2143: syntax error : missing ';' before '<<'
Error executing cl.exe.
3.obj - 13 error(s), 0 warning(s)
???
3.cpp
C:\c++ storage\3.cpp(7) : error C2143: syntax error : missing ';' before '<<'
C:\c++ storage\3.cpp(7) : error C2501: 'cout' : missing storage-class or type specifiers
C:\c++ storage\3.cpp(7) : error C2143: syntax error : missing ';' before '<<'
C:\c++ storage\3.cpp(9) : error C2143: syntax error : missing ';' before '>>'
C:\c++ storage\3.cpp(9) : error C2501: 'cin' : missing storage-class or type specifiers
C:\c++ storage\3.cpp(9) : error C2143: syntax error : missing ';' before '>>'
C:\c++ storage\3.cpp(12) : error C2143: syntax error : missing ';' before 'if'
C:\c++ storage\3.cpp(13) : error C2143: syntax error : missing ';' before '{'
C:\c++ storage\3.cpp(13) : error C2447: missing function header (old-style formal list?)
C:\c++ storage\3.cpp(20) : error C2143: syntax error : missing ';' before '<<'
C:\c++ storage\3.cpp(20) : error C2501: 'cout' : missing storage-class or type specifiers
C:\c++ storage\3.cpp(20) : error C2086: 'cout' : redefinition
C:\c++ storage\3.cpp(20) : error C2143: syntax error : missing ';' before '<<'
Error executing cl.exe.
3.obj - 13 error(s), 0 warning(s)
???
0
#7 Feb 23rd, 2003
Make sure your whole program is enclosed in
C++ Syntax (Toggle Plain Text)
#include<iostream.h> int main() { [ CODE GOES HERE ] return (0); }
•
•
Join Date: Feb 2003
Posts: 129
Reputation:
Solved Threads: 1
•
•
•
•
Originally Posted by fastcarz3
can anyone come up with a solution for this ? real quick for me?
If anyone could this for me thanks.
If you can't do the course go find something more suitable.
![]() |
Similar Threads
- factorial using a for loop (C++)
- Factorial program (Java)
- Calculate the factorial of a number (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Problem with basic templates on GCC
- Next Thread: Recursion
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






