Write a MATLAB program to add subtract multiply or divide th

Write a MATLAB program to add, subtract, multiply or divide the numbers based on the choice of operation entered by the user. Your program should accept only two numbers as inputs.

Solution

clc
clear
a=input(\'enter the 1st value=\');
b=input(\'enter the 2nd value=\');
disp(\'enter the operation you want to perform on given numbers.1 for addition,2 for subtraction,3 for multiplication,4 for division\');
t=input(\'enter the number corresponding to required operation=\');
if t~=1&&t~=2&&t~=3&&t~=4
disp(\'enter a valid number corresponding to given operation\')
else
if t==1
c=a+b;
elseif t==2
c=a-b;
elseif t==3
c=a*b;
elseif t==4
c=a/b;
end
disp(\'result obtained for required operation performed on given numbers\')
c
end

 Write a MATLAB program to add, subtract, multiply or divide the numbers based on the choice of operation entered by the user. Your program should accept only t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site