Advertisement
Sierra_ONE

Focus on the Positive

Oct 8th, 2023
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.37 KB | Source Code | 0 0
  1. /*
  2. 11. Focus on the Positive
  3. I'm tired of everyone being so down. It seems like all they give me these days are negative numbers, I barely see positive ones anymore. Let's change that! Let us only show the people the positive numbers! I'm going to give you four numbers and I want you to add only the positive numbers. (NOTE: Round off to two decimal places)
  4.  
  5. Inputs
  6. 1. The four numbers
  7. */
  8.  
  9.  
  10. #include <stdio.h>
  11.  
  12. int main(){
  13.  
  14.     float num1, num2, num3, num4;
  15.  
  16.     printf("Enter the first number: ");
  17.     scanf("%f", &num1);
  18.     printf("Enter the second number: ");
  19.     scanf("%f", &num2);
  20.     printf("Enter the third number: ");
  21.     scanf("%f", &num3);
  22.     printf("Enter the fourth number: ");
  23.     scanf("%f", &num4);
  24.  
  25.     if (num1 > 0 && num2 > 0 && num3 > 0 && num4 > 0){
  26.         printf("Sum of all positive numbers = %.2f", num1 + num2 + num3 + num4);
  27.     }
  28.     else if (num1 > 0 && num2 > 0 && num3 > 0){
  29.         printf("Sum of all positive numbers = %.2f", num1 + num2 + num3);
  30.     }
  31.     else if (num2 > 0 && num3 > 0 && num4 > 0){
  32.         printf("Sum of all positive numbers = %.2f", num2 + num3 + num4);
  33.     }
  34.     else if (num1 > 0 && num2 > 0 && num4 > 0){
  35.         printf("Sum of all positive numbers = %.2f", num1 + num2 + num4);
  36.     }
  37.     else if (num1 > 0 && num2 > 0){
  38.         printf("Sum of all positive numbers = %.2f", num1 + num2);
  39.     }
  40.     else if (num1 > 0 && num3 > 0){
  41.         printf("Sum of all positive numbers = %.2f", num1 + num3);
  42.     }
  43.     else if (num1 > 0 && num4 > 0){
  44.         printf("Sum of all positive numbers = %.2f", num1 + num4);
  45.     }
  46.     else if (num2 > 0 && num3 > 0){
  47.         printf("Sum of all positive numbers = %.2f", num2 + num3);
  48.     }
  49.     else if (num2 > 0 && num4 > 0){
  50.         printf("Sum of all positive numbers = %.2f", num2 + num4);
  51.     }
  52.     else if (num3 > 0 && num4 > 0){
  53.         printf("Sum of all positive numbers = %.2f", num3 + num4);
  54.     }
  55.     else if (num1 > 0){
  56.         printf("Sum of all positive numbers = %.2f", num1);
  57.     }
  58.     else if (num2 > 0){
  59.         printf("Sum of all positive numbers = %.2f", num2);
  60.     }
  61.     else if (num3 > 0){
  62.         printf("Sum of all positive numbers = %.2f", num3);
  63.     }
  64.     else if (num4 > 0){
  65.         printf("Sum of all positive numbers = %.2f", num4);
  66.     }
  67.     else{
  68.         printf("Sum of all positive numbers = %.2f");
  69.     }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement