Matlab编程,总是不对clear allclc;number=input('Please enter a number:');pp=number+1;a=0;b=0;i=2;while a==0 || b==0 a=0; b=0; if(pp-1)/4==0 a=1; for i=2:(pp-1) if pp/i==0 break; else
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/30 02:00:46
![Matlab编程,总是不对clear allclc;number=input('Please enter a number:');pp=number+1;a=0;b=0;i=2;while a==0 || b==0 a=0; b=0; if(pp-1)/4==0 a=1; for i=2:(pp-1) if pp/i==0 break; else](/uploads/image/z/8964308-20-8.jpg?t=Matlab%E7%BC%96%E7%A8%8B%2C%E6%80%BB%E6%98%AF%E4%B8%8D%E5%AF%B9clear+allclc%3Bnumber%3Dinput%28%27Please+enter+a+number%3A%27%29%3Bpp%3Dnumber%2B1%3Ba%3D0%3Bb%3D0%3Bi%3D2%3Bwhile+a%3D%3D0+%7C%7C+b%3D%3D0++++a%3D0%3B++++b%3D0%3B++++if%28pp-1%29%2F4%3D%3D0++++++++a%3D1%3B++++++++for+i%3D2%3A%28pp-1%29++++++++++++if+pp%2Fi%3D%3D0++++++++++++++++break%3B++++++++++++else)
Matlab编程,总是不对clear allclc;number=input('Please enter a number:');pp=number+1;a=0;b=0;i=2;while a==0 || b==0 a=0; b=0; if(pp-1)/4==0 a=1; for i=2:(pp-1) if pp/i==0 break; else
Matlab编程,总是不对
clear all
clc;
number=input('Please enter a number:');
pp=number+1;
a=0;
b=0;
i=2;
while a==0 || b==0
a=0;
b=0;
if(pp-1)/4==0
a=1;
for i=2:(pp-1)
if pp/i==0
break;
else
b=1;
end;
end;
end;
pp=pp+1;
end;
pp
——————————————————————------
题目是输入一个数字,计算出大于该输入数字的最小的质数(pp),同时这个质数可以表示为4*n-1.
运行总是跳不出来,求大神指教
刚刚开始学,写的东西很幼稚.
但是老师什么都没教,就让我们写这种东西.真是苦恼
其实我觉得逻辑没什么问题,但一运行循环就是不停止.
Matlab编程,总是不对clear allclc;number=input('Please enter a number:');pp=number+1;a=0;b=0;i=2;while a==0 || b==0 a=0; b=0; if(pp-1)/4==0 a=1; for i=2:(pp-1) if pp/i==0 break; else
flag = 0;
number=input('Please enter a number:');
num = number;
while flag == 0
num = num+1;
if isprime(num)
if ~mod((num-1),4)
flag = 1;
end
end
end
disp(num)