作业帮 > 英语 > 作业

matlab yi dao wen ti~ Thank you!

来源:学生作业帮 编辑:拍题作业网作业帮 分类:英语作业 时间:2024/06/04 10:22:49
matlab yi dao wen ti~ Thank you!
Write a program that would take an integer number from the user and output to the screen all possible triplet combinations that would multiply to the given number.
Each set of three numbers (triplets) should appear only once. This means that for a correct answer the user will not see both outputs “5 3 1” and “3 5 1”. Your program should include the set of numbers 1, 3, and 5 only once. Here is an example for finding all the triplets that will multiply to 24.
This is a solution for 24!
1 1 24
1 2 12
1 3 8
1 4 6
2 2 6
2 3 4
After each trial, the program should ask the user if they would like to continue. If the answer is “yes” the program should repeat. If the answer is “no” the program should say goodbye and exit.
程序如下:
str='Yes';
while strcmp(str,'Yes')==1
n=str2num(input('Please input a number: ', 's'));
for i=n:-1:1
for j=1:i
for k=1:j
if n==i*j*k
disp([k j i])
end
end
end
end
str='';
while strcmp(str,'Yes')==0 && strcmp(str,'No')==0
str=input('Continue?','s');
end
end
disp('Goodbye!')