#include <iostream.h>
#include <stdlib.h>
int main()
{
for(int x=1; x<=10; x++)
{
int n_ = 1;
//1! = 1
n_ = ((n_*x)-1)*x;
//2! = 1! *2
//3! = 2! *3
//4! = 3! *4
std::cout << n_ << " ";
}
system("PAUSE");
return 0;
}
#include <iostream.h>
#include <stdlib.h>
int main()
{
for(int x=1; x<=10; x++)
{
int n_ = 1;
//1! = 1
n_ = ((n_*x)-1)*x;
//2! = 1! *2
//3! = 2! *3
//4! = 3! *4
std::cout << n_ << " ";
}
system("PAUSE");
return 0;
}
What do you want? I cannot understand.
an error: please change :
toCode:#include <iostream.h>
Code:#include <iostream> using namespace std; // Edited
Hello, everyone.
what numbers to you expect, and what numbers are printed out?
form code I expect to see 0 2 6 12 20 ....
1. You are using older header files so you don't have to name the namespace for cout. Get rid of the std:: in front of cout.
Ignore my 2 and 3 I didn't see the last part down there it's tooo early.
That should get you started. Keep working. Have a nice day.
Last edited by DISGUISED; 05-10-2002 at 09:30 AM.
WTH? Why would you remove the .h? Your compiler may be different?
Code:#include <iostream> using namespace std; void main() { int nResult = 1; // 1!=1 for(int i=2; i<=10; i++) { nResult *= i; cout << nResult << "\t"; } }
Hello, everyone.
if you use std::cout, that implies you are using namespace standard. All compilers I know that use namespaces also use the convention that files listed in the #include section don't use the .h extension. If your compiler requires you to use the .h extension when listing iostream then it probably doesn't use namespaces and listing the namespace will cause an error. So, it's probably one or the other, iostream alone with namespace std, or iostream.h without namespace standard.
since n_ is assigned the value of 1 each time through the loop, the expression (n_*x) is the same as x so you end up with the expression (x - 1)*x. Whether that is as intended or not is not clear.
All C++ standard header files have no .h ; .h is old C style; A C++ programmer should use C++ standard.
Hello, everyone.
[quote]
[quote]Code:int main() { for(int x=1; x<=10; x++) { int n_ = 1;
Considering this Board. C-PROGRAMMING. C++ methods are in the way. C would never allow u to declare any variable after u have started writing the body of a function. U should do it before the code part.
-Sriharsha.
Help everyone you can
Sorry Sorry Sorry.
I just did not pay heed to the board. I justtyped new threads and I just did not look at the board...
-Sriharsha.
Help everyone you can
I want to print:
2! = 1!*2
2! = 2
3! = 2!*3
3! = 6
4! = 3!*4
4! = 24
5! = 4!*5
5! = 120
6! = 5!*6
6! = 720
7! = 6!*7
7! = 5040
Code:#include <iostream> using namespace std; void main() { int nResult = 1; // 1!=1 for(int i=2; i<=10; i++) { nResult *= i; cout << i << "! = " << i-1 << "! *" << i << endl; cout << i << "i = " << nResult << endl; } }
Hello, everyone.
many a compiler is available that doesn't comply with the current standards. Unless you want to be another MS and demand that we all "update" as soon as the newest and "greatest" becomes available, taking "older" compilers into account is still necessary. In fact, I suspect that there are many more "non-compliant" compilers in use at this time than compliant ones.
The code I listed can run on VC6 / BCB / BC++ / GNU C++ .
Hello, everyone.
VC++ 6 and BCB 5, but not earlier versions. I don't know about others here, but I not about to buy the latest and greatest when what I have suits my needs. So I'll stick with what I have, be aware of the newer techniques, and be cognizant that many of us can't use them.