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; b<100; b++) // constraints for b: a<b<100
  18. for (c = b+1; c<100; c++) // constraints for c: b<c<100
  19. if ( ( a+b+c == 100 ) &&
  20. ( a*b*c == 7680 ) )
  21. {
  22. // since we found it and we only wanted to find one such
  23. // triple, we print it out and return 0 from main, termi-
  24. // nating the execution of the program
  25.  
  26. cout << a << " " << b << " " << c << endl;
  27.  
  28. return 0;
  29. }
  30.  
  31. // return 0 from main (this return statement is only reached
  32. // if we fail to find the triple we're looking for)
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
8 12 80