fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int parent1[2], parent2[2], offspring[2];
  8.  
  9. // Input sifat dari kedua orang tua dan keturunan
  10. for (int i = 0; i < 2; i++) {
  11. cin >> parent1[i];
  12. }
  13. for (int i = 0; i < 2; i++) {
  14. cin >> parent2[i];
  15. }
  16. for (int i = 0; i < 2; i++) {
  17. cin >> offspring[i];
  18. }
  19.  
  20. // Hitung jumlah genotipe dari F1
  21. int tall_count = 0; // Hitung tinggi tanaman
  22. int many_count = 0; // Hitung jumlah anakan
  23.  
  24. // Menghitung rasio F1 untuk tinggi tanaman
  25. if (parent1[0] == 2 && parent2[0] == 2) tall_count = 4; // TT x TT
  26. else if (parent1[0] == 2 && parent2[0] == 1) tall_count = 3; // TT x Tt
  27. else if (parent1[0] == 2 && parent2[0] == 0) tall_count = 2; // TT x tt
  28. else if (parent1[0] == 1 && parent2[0] == 1) tall_count = 2; // Tt x Tt
  29. else if (parent1[0] == 1 && parent2[0] == 0) tall_count = 1; // Tt x tt
  30. else if (parent1[0] == 0 && parent2[0] == 0) tall_count = 0; // tt x tt
  31. else if (parent1[0] == 0 && parent2[0] == 1) tall_count = 1; // tt x Tt
  32. else if (parent1[0] == 0 && parent2[0] == 2) tall_count = 2; // tt x TT
  33.  
  34. // Menghitung rasio F1 untuk jumlah anakan
  35. if (parent1[1] == 2 && parent2[1] == 2) many_count = 4; // BB x BB
  36. else if (parent1[1] == 2 && parent2[1] == 1) many_count = 3; // BB x Bb
  37. else if (parent1[1] == 2 && parent2[1] == 0) many_count = 2; // BB x bb
  38. else if (parent1[1] == 1 && parent2[1] == 1) many_count = 2; // Bb x Bb
  39. else if (parent1[1] == 1 && parent2[1] == 0) many_count = 1; // Bb x bb
  40. else if (parent1[1] == 0 && parent2[1] == 0) many_count = 0; // bb x bb
  41. else if (parent1[1] == 0 && parent2[1] == 1) many_count = 1; // bb x Bb
  42. else if (parent1[1] == 0 && parent2[1] == 2) many_count = 2; // bb x BB
  43.  
  44. // Total kemungkinan genotipe
  45. int total_combinations = 16; // 4 (tinggi) * 4 (anakan)
  46.  
  47. // Hitung persentase
  48. int desired_tall = (offspring[0] == 0) ? 0 : (offspring[0] == 1) ? (tall_count > 0) : tall_count;
  49. int desired_many = (offspring[1] == 0) ? 0 : (offspring[1] == 1) ? (many_count > 0) : many_count;
  50.  
  51. int successful_combinations = desired_tall * desired_many;
  52.  
  53. double percentage = (double)successful_combinations / total_combinations * 100;
  54.  
  55. // Output persentase
  56. cout << fixed << setprecision(2) << percentage << "%" << endl;
  57.  
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0.01s 5284KB
stdin
22
00
00
stdout
0.00%