what is problem here?

#include <iostream>
int main()
{
using namespace std;
int n;
long k;
cin>>n;
if(n>0&&n<=100)
{
k=n*(n-1)*(n-2);
cout<<k<<endl;
}
system("pause");
return 0;
}
try to put (using namespace std;) outside the function after #include
and change system("pause") to system("PAUSE")
closed account (Gz64jE8b)
It compiled without any errors.

abdelelbouhy both of your suggestions won't make a difference to his program.
it works succesfully but there is one site ,i take this problem form there it works 90% there. it is that problem :


Forest residents have decided to hold a hockey tournament between the N teams. How many ways can be distributed sets of gold, silver and bronze medals, if one prize may take only one team?

Specifications

Input

In a single line located a unique natural number N, does not exceed 100.

Output

Single number - the required number of ways.


Example input
17
Example output
4080
You need to solve how many 3(=k) permutations is in n many team.
There is mathematical formula so solve it:
total numbers of permutations=n!/[(n-k)!]
so if there is 17 teams trying to get 3 medals the answer is:
17!/[(17-3)!]
=17!/(14!)
=4080

x!=1*2*3*.......*x
Last edited on
but it is same with mine.
n!/(n-3)!=n*(n-1)*(n-2)*(n-3)!/(n-3)!=n*(n-1)*(n-2)
Think ahead.. :)

1
2
3
4
5
if(n>0&&n<=100)
{
k=n*(n-1)*(n-2);
cout<<k<<endl;
}


That runs only ONCE!!!

i you give say number 7(=n)... what happens?
k(?)(try some variable like result...) would be after:
k=n*(n-1)*(n-2); where n=7
k=7*(7-1)*(7-2)
k=7*6*5
k=210

Last edited on
hmm,thanks
Topic archived. No new replies allowed.