Answer to Question #301675 in Algorithms for keirdeiparine

Question #301675

Given two numbers X and Y, create a program that determines the difference between X and Y using if-else. If X - Y is negative, compute R = X + Y; if X - Y is zero, compute R = 2X + 2Y; and if X - Y is positive, compute R = X * Y. Print the values of X, Y, and R.


1
Expert's answer
2022-02-23T12:18:51-0500

Program on python:

X = float(input())
Y = float(input())

if X-Y < 0:
    R = X + Y
elif X-Y == 0:
    R = 2*X + 2*Y
else:
    R = X*Y
print(f'X = {X},  Y = {Y},  R = {R}')


Program on C:

#include <stdio.h>

int main() {
    double X, Y, R;

    scanf("%lf %lf", &X, &Y);
    if (X-Y < 0) {
        R = X + Y;
    }
    else if (X-Y == 0) {
        R = 2*X + 2*Y;
    }
    else {
        R = X*Y;
    }
    printf("X = %lf,  Y = %lf,  R = %lf", X, Y, R);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS