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.
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;
}
Comments
Leave a comment