Removing the space between %2d in a string statement.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
a=3;
b=4;
c=5;
[check,report]=ispythag(a,b,c);
function [check,report]=ispythag(a,b,c)
if (a^2)+(b^2)==(c^2)
check=true;
else
check=false;
end
formatspec_check='check:%2d\n';
formatspec_true='report:(%2d,%2d,%2d) form a Pythagorean triple.\n';
formatspec_false_1='report:c must be %2d to form a Pythagorean triple with a and b.\n';
formatspec_false_2='report:There is no value of c that can form a Pythagorean triple with a and b.\n';
integer=sqrt((a^2)+(b^2));
s=sqrt((a^2)+(b^2));
if check==true
report=sprintf(formatspec_true,a,b,c);
else
if s==floor(s)
report=sprintf(formatspec_false_1,integer);
else
report=sprintf(formatspec_false_2);
end
end
fprintf(formatspec_check,check);
fprintf(report);
end
%Shown in the code above, the "formatspec_true='report:(%2d,%2d,%2d) form a Pythagorean triple.\n';" line of the code assigns the statement to the variable formatspec_true.
However when I print this variable using the variable 'report' there are spaces between the numbers.
So example if the output of the function will be
"report: ( 3, 4, 5) form a Pythagorean triple."
How do I turn this into
"report: (3,4,5) form a Pythagorean triple."
where there are no space in between the numbers.
0 Kommentare
Antworten (1)
Siehe auch
Kategorien
Mehr zu Assembly 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!