So one of the examples on the google c++ course is this:
How many ways can you arrange 6 different books, left to right, on a shelf?
This time we will just give you the solution and let you write the program: 720.
Heres the link:
http://code.google.com/edu/languages/cpp/basics/getting-started.html
So after thinking for a bit I started writing a it, and it took a good 15 minutes before it was all tweaked, but here is the code I came up with. I know it is right because it spits out the right answer, and it makes perfect sense. What I was wondering was if there is an easier way anyone sees?
Some background, this is my second day writing in c++, the first was on labor day when I started to learn it, so im very new. I have written 15ish programs, some easy, some which i am somewhat impressed with.
heres my code:
#include <iostream>
using namespace std;
int main() {
int a, b,c,d,e,f,n;
for (a=0;a<=5;a++){
for (b=0;b<=5;b++)
if (b!=a)
for(c=0;c<=5;c++)
if (c!=b && c!=a)
for(d=0;d<=5;d++)
if (d!=c && d!=b && d!=a)
for(e=0;e<=5;e++)
if(e!=d && e!=c && e!=b && e!=a)
for(f=0;f<=5;f++)
if(f!=e && f!=d && f!=c && f!=b && f!=a) n++;
}
cout<<n<<endl;
return 0;
}