CSCI-1060 SCIENTIFIC PROGRAMMING Quiz (10/9/2017) udent W Use an if-statement to
ID: 3589178 • Letter: C
Question
CSCI-1060 SCIENTIFIC PROGRAMMING Quiz (10/9/2017) udent W Use an if-statement to write a script that works like following. It asks a user to enter an integer. If the entered number is not integer, the script should say asked for an integer.' If the number is integer and divisible by 2, the message displayed on the screen should say: 'The integer is even.' If the number is integer and not divisible by 2, the script should say: "The integer is odd. 1. NOTES: a number is integer if the difference between fix(number) and number is 0; a number is divisible by 2 if rem(number, 2) is 0. witch-statement to write a script that asks a user for his/her favorit er picks red, the script should display: 'I like it too.' If the user pic e script should display: This is my son's favorite color. If theus script should display: "My granddaughter's color. If the user pi e script should display: My wife's color.' For any other colorExplanation / Answer
Use an if-statement to write a script in matlab that works like following. It asks a user to enter an integer. If entered number is not integer. The script should say : I asked for an integer. If the number is integer and divisible by 2, the message displayed on the screen should say: the integer is even
while int == 0 % Continue looping until ‘good’ number entered
x = input('Enter the number: ');
if isinteger(x) && rem(x,1)==0
int = 1; % ‘Real-or-Integer’ number
else
fprintf(1,' I asked for an integer number. ')
end
if isinteger(x) && rem(x%2)==0
fprintf(' The integer is even. ')
end
if isinteger(x) && rem(x%2)0
fprintf(' The integer is odd. ')
end
output:
Enter the number:4
The integer is even