fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. #define PI 3.14159
  8.  
  9. void divide() {
  10. float a, b;
  11. double quotient;
  12.  
  13. cout << "Nhap so a: ";
  14. cin >> a;
  15.  
  16. cout << "Nhap so b: ";
  17. cin >> b;
  18.  
  19. if (b == 0)
  20. {
  21. cout << "Phep chia khong hop le\n";
  22. return;
  23. }
  24.  
  25. cout << "Thuong so la: " << fixed << setprecision(3) << a / b << '\n';
  26. }
  27.  
  28. void sum() {
  29. int a;
  30. float b, total;
  31.  
  32. cout << "Nhap so a: ";
  33. cin >> a;
  34.  
  35. cout << "Nhap so b: ";
  36. cin >> b;
  37.  
  38. total = a + b;
  39. cout << "Tong hai so la: " << fixed << setprecision(3) << total << '\n';
  40. }
  41.  
  42. void calculate_age() {
  43. int year;
  44.  
  45. cout << "Nhap nam sinh: ";
  46. cin >> year;
  47.  
  48. cout << "Tuoi cua ban: " << 2025 - year << '\n';
  49. }
  50.  
  51. void ascii() {
  52. char character;
  53. int number;
  54.  
  55. cout << "Nhap ky tu: ";
  56. cin >> character;
  57.  
  58. cout << "Nhap so: ";
  59. cin >> number;
  60.  
  61. cout << "Ma ASCII cua ky tu " << character << " la: " << int(character) << '\n';
  62. cout << "Ky tu co ma ASCII bang " << number << " la: " << char(number) << '\n';
  63.  
  64. }
  65.  
  66. void perimeter_and_area_circle() {
  67. float radius;
  68.  
  69. cout << "Nhap ban kinh hinh tron: ";
  70. cin >> radius;
  71.  
  72. cout << "Chu vi hinh tron la: " << fixed << setprecision(5) << 2 * PI * radius << '\n';
  73. cout << "Dien tich hinh tron la: " << fixed << setprecision(5) << PI * pow(radius, 2) << '\n';
  74. }
  75.  
  76. void perimeter_and_area_circular_cylinder() {
  77. float radius, height;
  78.  
  79. cout << "Nhap ban kinh hinh tru: ";
  80. cin >> radius;
  81.  
  82. cout << "Nhap chieu cao hinh tru: ";
  83. cin >> height;
  84.  
  85. float dt_day = PI * pow(radius, 2);
  86. float dt_xq = PI * 2 * radius * height;
  87. float tt = dt_day * height;
  88.  
  89. cout << "Dien tich day hinh tru: " << fixed << setprecision(5) << dt_day << '\n';
  90. cout << "Dien tich xung quanh hinh tru: " << fixed << setprecision(5) << dt_xq << '\n';
  91. cout << "The tich hinh tru: " << fixed << setprecision(5) << tt << '\n';
  92. }
  93.  
  94. void compute_equation() {
  95. float x;
  96.  
  97. cout << "Nhap vao gia tri x: ";
  98. cin >> x;
  99.  
  100. float y1 = 4 * (pow(x, 2) + 10 * x * sqrt(x) + 3 * x + 1);
  101. float y2 = (sin(PI * pow(x, 2)) + sqrt(pow(x, 2) + 1)) / (exp(2 * x) + cos(x * PI / 4));
  102.  
  103. cout << "Gia tri bieu thuc y1: " << fixed << setprecision(4) << y1 << '\n';
  104. cout << "Gia tri bieu thuc y2: " << fixed << setprecision(4) << y2 << '\n';
  105. }
  106.  
  107. void exchange_money() {
  108. int N;
  109.  
  110. cout << "Nhap so tien N: ";
  111. cin >> N;
  112.  
  113. int count1 = 0, count2 = 0, count5 = 0, count10 = 0;
  114. count10 = N / 10;
  115. N = N % 10;
  116. count5 = N / 5;
  117. N = N % 5;
  118. count2 = N / 2;
  119. N = N % 2;
  120. count1 = N;
  121. cout << "So luong tien sau khi doi: " << count10 << " " << count5 << " " << count2 << " " << count1 << '\n';
  122. }
  123.  
  124. int main() {
  125. divide();
  126. sum();
  127. calculate_age();
  128. ascii();
  129. perimeter_and_area_circle();
  130. perimeter_and_area_circular_cylinder();
  131. compute_equation();
  132. exchange_money();
  133. return 0;
  134. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Nhap so a: Nhap so b: Thuong so la: -30437873067359089983488.000
Nhap so a: Nhap so b: Tong hai so la: -1584787968.000
Nhap nam sinh: Tuoi cua ban: -19908
Nhap ky tu: Nhap so: Ma ASCII cua ky tu  la: 0
Ky tu co ma ASCII bang 0 la: 
Nhap ban kinh hinh tron: Chu vi hinh tron la: 0.00000
Dien tich hinh tron la: 0.00000
Nhap ban kinh hinh tru: Nhap chieu cao hinh tru: Dien tich day hinh tru: 0.00000
Dien tich xung quanh hinh tru: 0.00000
The tich hinh tru: 0.00000
Nhap vao gia tri x: Gia tri bieu thuc y1: 4.0000
Gia tri bieu thuc y2: 0.5000
Nhap so tien N: So luong tien sau khi doi: 107269324 1 1 1