Advertisement
YouKnowWho07

If, IfElseIf, NestedIf

Dec 1st, 2023
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. /*
  2. /// if
  3.  
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     int num1, num2, num3;
  9.     printf("Enter three numbers: ");
  10.     scanf("%d %d %d", &num1, &num2, &num3);
  11.  
  12.     // Maximum calculation using only if statements
  13.     if (num1 > num2 && num1 > num3)
  14.     {
  15.         printf("Maximum number is: %d\n", num1);
  16.     }
  17.     if (num2 > num1 && num2 > num3) {
  18.         printf("Maximum number is: %d\n", num2);
  19.     }
  20.     if (num3 > num1 && num3 > num2) {
  21.         printf("Maximum number is: %d\n", num3);
  22.     }
  23.     return 0;
  24. }
  25. */
  26.  
  27. /*
  28. /// If-Else If-Else
  29. #include <stdio.h>
  30.  
  31. int main()
  32. {
  33.     int num1, num2, num3;
  34.     printf("Enter three numbers: ");
  35.     scanf("%d %d %d", &num1, &num2, &num3);
  36.  
  37.     if (num1 >= num2 && num1 >= num3)
  38.     {
  39.         printf("Maximum number is: %d\n", num1);
  40.     }
  41.     else if (num2 >= num1 && num2 >= num3) {
  42.         printf("Maximum number is: %d\n", num2);
  43.     }
  44.     else {
  45.         printf("Maximum number is: %d\n", num3);
  46.     }
  47.     return 0;
  48. }
  49. */
  50.  
  51. /*
  52. /// Nested If
  53. #include <stdio.h>
  54.  
  55. int main() {
  56.     int num1, num2, num3;
  57.  
  58.     // Input
  59.     printf("Enter three numbers: ");
  60.     scanf("%d %d %d", &num1, &num2, &num3);
  61.  
  62.     // Maximum calculation using nested if-else statements
  63.     if (num1 >= num2)
  64.     {
  65.         if (num1 >= num3) {
  66.             printf("Maximum number is: %d\n", num1);
  67.         }
  68.         else {
  69.             printf("Maximum number is: %d\n", num3);
  70.         }
  71.     }
  72.     else {
  73.         if (num2 >= num3) {
  74.             printf("Maximum number is: %d\n", num2);
  75.         }
  76.         else {
  77.             printf("Maximum number is: %d\n", num3);
  78.         }
  79.     }
  80.  
  81.     return 0;
  82. }
  83.  
  84. */
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement