fork download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n;
  10. int sum=0;
  11. //cin>>n;
  12. n = 5;
  13. for(int i=1;i<=n;++i)
  14. {
  15. sum=sum+pow(i,3);
  16. //sum = sum + int(pow(i, 3));
  17. //sum = sum + trunc(pow(i, 3));
  18. //sum = sum + round(pow(i, 3));
  19. double anhyeuem = pow(i, 3);
  20. //sum = sum + anhyeuem;
  21. //sum = sum + int(anhyeuem);
  22. int k = (int) anhyeuem;
  23. cout <<i<<"^3 = " <<anhyeuem<<" (1)"<<endl;
  24. cout <<i<<"^3 = " <<k<<" (2)"<<endl;
  25. printf("%d^3 = %0.16lf (3)\n", i, anhyeuem);
  26.  
  27. if (anhyeuem == 124.999999999999995) cout << "\n\n\nhahaha1" << endl;
  28. if (anhyeuem == 124.999999999999997) cout << "hahaha2" << endl;
  29. if (anhyeuem == 125) cout << "hahaha3" << endl;
  30.  
  31. double anhyeuem2 = 124.999999999999995;
  32. if (anhyeuem == 125) cout << anhyeuem2<<endl;
  33. if (anhyeuem == 125) printf("%0.16lf\n", anhyeuem2);
  34.  
  35. cout << "Current total: " << sum << endl << endl;
  36. }
  37. cout << "\n---------------------\n";
  38. cout << "1^3 = " << pow(1,3) << endl;
  39. cout << "2^3 = " << pow(2,3) << endl;
  40. cout << "3^3 = " << pow(3,3) << endl;
  41. cout << "4^3 = " << pow(4,3) << endl;
  42. cout << "5^3 = " << pow(5,3) << endl;
  43. cout << "\n---------------------\n";
  44. cout << "Sum = " << sum << endl;
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 2688KB
stdin
Standard input is empty
stdout
1^3 = 1   (1)
1^3 = 1   (2)
1^3 = 1.0000000000000000   (3)
Current total: 1

2^3 = 8   (1)
2^3 = 8   (2)
2^3 = 8.0000000000000000   (3)
Current total: 9

3^3 = 27   (1)
3^3 = 27   (2)
3^3 = 27.0000000000000000   (3)
Current total: 36

4^3 = 64   (1)
4^3 = 64   (2)
4^3 = 64.0000000000000000   (3)
Current total: 100

5^3 = 125   (1)
5^3 = 125   (2)
5^3 = 125.0000000000000000   (3)



hahaha1
hahaha2
hahaha3
125
125.0000000000000000
Current total: 225


---------------------
1^3 = 1
2^3 = 8
3^3 = 27
4^3 = 64
5^3 = 125

---------------------
Sum = 225