fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // Penamaan variabel
  7. // a-z, A-Z, _, 0-9
  8. // Di depan ga boleh angka -> kali2
  9. // Ga boleh sama dgn keyword
  10. // Tips: buat nama variabel se-deskriptif mungkin
  11.  
  12. // 4 primitive data types
  13. // bil bulat
  14. int angka; // -2^31 -- 2^31 - 1
  15. long long panjang; // -2^63 -- 2^63 - 1
  16. unsigned int positif; // 0 -- 2^32 - 1
  17. angka = 2147483647;
  18. cout << angka << endl;
  19.  
  20. // bil desimal
  21. double desimal = 1.5;
  22. cout << desimal << endl;
  23.  
  24. // character/simbol -> ASCII
  25. char hurufA = 'A';
  26. cout << hurufA << endl;
  27. char hurufB = hurufA+1;
  28. cout << hurufB << endl;
  29.  
  30. // boolean
  31. bool benar = true;
  32. bool salah = false;
  33.  
  34. // Operasi
  35. int x = 1, y = 2, hasil;
  36. hasil = x+y;
  37. hasil = x-y;
  38. hasil = x*y;
  39. hasil = x/y;
  40. hasil = x%y;
  41. // Pembagian = hasil bagi
  42. // Modulo = sisa bagi
  43. // 11/3 = 3 + 2/3 -> 11/3 = 3, 11%3 = 2
  44.  
  45. hasil += x; // sama dengan hasil = hasil+x;
  46. // sama juga utk operasi -, *, /, %
  47.  
  48. // increment & decrement
  49. hasil++; // sama dengan hasil = hasil+1;
  50. hasil--; // sama dengan hasil = hasil-1;
  51.  
  52. // Control Structure
  53. // Linear
  54. // Branching / Percabangan
  55. // Looping / Perulangan
  56.  
  57. angka = 2;
  58. switch(angka) {
  59. case 1:
  60. cout << "Masuk case 1" << endl;
  61. break;
  62. case 2:
  63. cout << "Masuk case 2" << endl;
  64. break;
  65. default:
  66. cout << "Masuk case default" << endl;
  67. break;
  68. }
  69.  
  70. if(!(angka > 0)) {
  71. cout << "Masuk if" << endl;
  72. }
  73. else {
  74. cout << "Masuk else" << endl;
  75. }
  76.  
  77. // Ternary operation
  78. if(hurufA == 'A') {
  79. angka = 1;
  80. }
  81. else {
  82. angka = 2;
  83. }
  84. angka = (hurufA == 'A') ? 1 : 2;
  85.  
  86. /*
  87. 1. https://tlx. toki.id/problems/troc-1/A
  88. 2. https://tlx. toki.id/problems/troc-2/A
  89. 3. https://tlx. toki.id/problems/troc-32/A
  90. 4. https://tlx. toki.id/problems/osn-2009/2A
  91. https://ideone. com/4tlSgK
  92.  
  93. 5. Buatlah sebuah program untuk mengubah nilai angka
  94. menjadi huruf.
  95. A: 86-100
  96. B: 71-85
  97. C: 56-70
  98. D: 41-55
  99. E: 0-40
  100.  
  101. Contoh input:
  102. 80
  103.  
  104. Contoh output:
  105. B
  106. https://ideone. com/stcfdR
  107. */
  108.  
  109. return 0;
  110. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
2147483647
1.5
A
B
Masuk case 2
Masuk else