a=input('enter number'); b=input('enter number'); c=input('enter operator'); switch c case'+' disp(a+b); case'-' disp(a-b); end
Mostrar comentarios más antiguos
a=input('enter number');
b=input('enter number');
c=input('enter operator');
switch c
case'+'
disp(a+b);
case'-'
disp(a-b);
end
guyzz in this program i dnt knw about operator and second there is an error of operator.. make this progarm true and also from this switch statement..nor other.thak u.
Respuestas (2)
James Tursa
el 30 de Abr. de 2015
Input variable c as a string. E.g.,
c = input('enter operator','s')
3 comentarios
waqas khosa
el 30 de Abr. de 2015
James Tursa
el 30 de Abr. de 2015
Have you tried it?
waqas khosa
el 30 de Abr. de 2015
Kelvin Viroja
el 22 de Ag. de 2016
0 votos
U can easily do it by using if loop
a=input('enter number'); b=input('enter number'); c=input('enter operator','s'); d='+'; e='-';
if strcmp(c,d) G=a+b; else if strcmp (c,e) G=a-b; else end
disp(G);
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!