fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a, b, c;
  8. int k = 100;
  9.  
  10. // finds three natural numbers a, b, and c,
  11. // such that all of the following holds
  12. // a) a < b < c
  13. // b) a + b + c = 100
  14. // c) a * b * c = 7680
  15.  
  16. for (a = 1; a<100; a++) // a cannot be more than 100
  17. for (b = a+1; a+b<100; b++) // constraints for b: a<b<100 and
  18. // a+b<100 (for c>0)
  19. {
  20. c = 100 - a - b; // no need to loop over c since
  21. // we can find it from a and b
  22.  
  23. if ( a*b*c == 7680 )
  24. {
  25. // since we found it and we only wanted to find one such
  26. // triple, we print it out and return 0 from main, termi-
  27. // nating the execution of the program
  28.  
  29. cout << a << " " << b << " " << c << endl;
  30.  
  31. return 0;
  32. }
  33. }
  34.  
  35. // return 0 from main (this return statement is only reached
  36. // if we fail to find the triple we're looking for)
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
8 12 80