Program 1:
num1 = 10;
num2 = 20;
num3 = 30;
large = 0;
if (num1 > num2)
if (num1 > num3)
large = num1;
else
large = num3;
end
elsif(num2 > num1)
if (num2 > num3)
large = num2;
else
large = num3;
end
else
large = num3;
end
print("Largest value is : ", large);
Program 2:
num1 = -10;
if (num1 < 0) == true
print("Number is NEGATIVE.");
else
print("Number is POSITIVE.");
end
Answer Program 1:
Output:
Explanation:
In the above program, we created num1, num2, num3, large that are initialized with 10, 20, 30, 0 respectively. Then we found the largest number among 3 numbers using nested if and printed the largest number.
Answer Program 2:
Output:
Explanation:
In the above program, we created a variable num1, which is initialized with -10. Then we checked num is POSITIVE or NEGATIVE using the if statement and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer