Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 11. Focus on the Positive
- 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)
- Inputs
- 1. The four numbers
- */
- #include <stdio.h>
- int main(){
- float num1, num2, num3, num4;
- printf("Enter the first number: ");
- scanf("%f", &num1);
- printf("Enter the second number: ");
- scanf("%f", &num2);
- printf("Enter the third number: ");
- scanf("%f", &num3);
- printf("Enter the fourth number: ");
- scanf("%f", &num4);
- if (num1 > 0 && num2 > 0 && num3 > 0 && num4 > 0){
- printf("Sum of all positive numbers = %.2f", num1 + num2 + num3 + num4);
- }
- else if (num1 > 0 && num2 > 0 && num3 > 0){
- printf("Sum of all positive numbers = %.2f", num1 + num2 + num3);
- }
- else if (num2 > 0 && num3 > 0 && num4 > 0){
- printf("Sum of all positive numbers = %.2f", num2 + num3 + num4);
- }
- else if (num1 > 0 && num2 > 0 && num4 > 0){
- printf("Sum of all positive numbers = %.2f", num1 + num2 + num4);
- }
- else if (num1 > 0 && num2 > 0){
- printf("Sum of all positive numbers = %.2f", num1 + num2);
- }
- else if (num1 > 0 && num3 > 0){
- printf("Sum of all positive numbers = %.2f", num1 + num3);
- }
- else if (num1 > 0 && num4 > 0){
- printf("Sum of all positive numbers = %.2f", num1 + num4);
- }
- else if (num2 > 0 && num3 > 0){
- printf("Sum of all positive numbers = %.2f", num2 + num3);
- }
- else if (num2 > 0 && num4 > 0){
- printf("Sum of all positive numbers = %.2f", num2 + num4);
- }
- else if (num3 > 0 && num4 > 0){
- printf("Sum of all positive numbers = %.2f", num3 + num4);
- }
- else if (num1 > 0){
- printf("Sum of all positive numbers = %.2f", num1);
- }
- else if (num2 > 0){
- printf("Sum of all positive numbers = %.2f", num2);
- }
- else if (num3 > 0){
- printf("Sum of all positive numbers = %.2f", num3);
- }
- else if (num4 > 0){
- printf("Sum of all positive numbers = %.2f", num4);
- }
- else{
- printf("Sum of all positive numbers = %.2f");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement