Filter löschen
Filter löschen

how can I write this simpler? (attachment)

1 Ansicht (letzte 30 Tage)
Young Lee
Young Lee am 29 Okt. 2018
Kommentiert: madhan ravi am 30 Okt. 2018
I have wrote the following code. just wondering if there is a much simpler way to write the same code.... I feel like Im going around long way for this.
a = input('Please enter amount 1~100c','s')
x = rem(str2num(a),25); y = floor(str2num(a)./25);
x1 = rem(x,10);
y1 = floor(x./10);
x2 = rem(x1,5); y2 = floor(x1./5);
x3 = rem(x2,1); y3 = floor(x2./1);
fprintf('Quaters (25c) X %d\n',y)
fprintf('Dimes (10c) X %d\n',y1)
fprintf('Nickels (5c) X %d\n',y2)
fprintf('Pennies (1c) X %d\n',y3)
sorry for inconvenience,
  2 Kommentare
madhan ravi
madhan ravi am 30 Okt. 2018
Upload your code
madhan ravi
madhan ravi am 30 Okt. 2018
We can’t debug a screenshot upload your code as text

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 30 Okt. 2018
a = input('Please enter amount 1~100c')
x = a/25
y = floor((a)/25)
x1 = x/10
y1 = floor(x/10)
x2 = x1/5
y2 = floor(x1/5)
x3 = x2
y3 = x2/1
fprintf('Quaters (25c) X %d\n',y)
fprintf('Dimes (10c) X %d\n',y1)
fprintf('Nickels (5c) X %d\n',y2)
fprintf('Pennies (1c) X %d\n',y3)
  2 Kommentare
Young Lee
Young Lee am 30 Okt. 2018
thank you
madhan ravi
madhan ravi am 30 Okt. 2018
Anytime :) did you solve your previous question?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by