Program 1:
num = 8.54;
if (num % 2 == 0)
println("Even Number");
else
println("Odd Number");
end
Program 2:
num = print("hello\n");
if (num % 2 == 0)
print("Even Number");
else
print("Odd Number");
end
Program 3:
num = 10;
if true
printf("Hello: %d", num);
else
printf("Hi: %d", num);
end
Program 4:
num = 10;
if (num == 10) == true
printf "Hello";
else
printf "Hi";
end
Program 5:
num1 = 10;
num2 = 20;
num3 = 30;
large = 0;
if num1 > num2 && num1 > num3
large = num1;
else if num2 > num1 && num2 > num3
large = num2;
else
large = num3;
end
print("Largest value is : ", large);
Answer Program 1:
Output:
Explanation:
The above program will generate a syntax error because println is not an inbuilt function in ruby.
Answer Program 2:
Output:
Explanation:
The above program will generate a runtime error because the print() function returns "nil" and we cannot use the "%" operator with the "nil" value.
Answer Program 3:
Output:
Explanation:
There is no error in this program. We can use true or false as the conditional expression.
Answer Program 4:
Output:
Explanation:
In the above program, we created a variable num initialized with 10. Then we checked the value of num in the if condition and printed the appropriate message.
Answer Program 5:
Output:
Explanation:
The above program will generate a syntax error because we cannot use else if in the ruby program. The correct program is given below,
need an explanation for this answer? contact us directly to get an explanation for this answer