-
Hey, poor bud!
Ah, your brain is used to keep your neck out of the rain!
Please be sure:
-
Indeed, the 6th floor is silly and naïve.
-
There are too many loops on the first floor, the program error on the second floor, i should be 1 to trunc(sqrt(a))+1 in the for loop, which may cause some numbers to fail to pass, the fourth floor is also, the fifth floor is also, when the decimal part of the value of sqrt(a) is less than the error, it will cause an error, the sixth floor is completely wrong, i is an integer variable, sqrt(n) is a real type, basically can not be compiled.
var i,a:longint;
beginreadln(a);
for i:=2 to trunc(sqrt(a))+1 doif a mod i=0 then
beginwriteln('no,it is not a primr.');
halt;end; writeln('yes, it is a primr.')
end.
-
Obviously, a prime number is a number that is not divisible by a number other than 1 and itself.
for i:=2 to trunc(sqrt(n)) doif n mod i=0 then exit(false);
exit(true);
The landlord can think for himself why sqrt is fine.
-
Once, you'll know
A lot of · These language questions
-
What's upstairs? Why do you still have multiple loops? Find all prime numbers that don't exceed a? Finding prime numbers only requires a cycle, which is the basic algorithm of pascal, and must be mastered!
program zhishu;
var a,f,n:longint;
beginf:=0;
readln(a);
for n:=2 to trunc(sqrt(a)) doif a mod n=0 then
begin f:=1;break;end;
if f=1 then writeln ('false') else writeln('true');
end.
-
a ,i,b,c : real;
There's a problem here.
Real numbers cannot be used as variables for loops.
It would be nice to change real to integer.
I also made this mistake a lot when I was just starting out.
-
var n,i:longint;b:boolean;
beginreadln(n);
if odd(n) then
beginb:=false;i:=1;
while (2<=trunc(sqrt(n)))and (b=false) do
if (n mod (i+1)<>0) then b:=true;
if b then writeln('yes') else writeln('no');
end;end.
Please refer to it. (Programming Beginners).
-
with a subroutine.
Specifically**I'll give it to you.
I didn't test it. program abc;
var i,k,m,n:longint;
function isprime(n:longint):boolean;
beginfunction:=true;
for i:=2 to sqrt(n) doif n mod i=0 then
beginfunction:=false;
exit;end;
end;begin
readln(n);
if isprime(n) then writeln('yes') else writeln('no');
end.Seek the correct solution.
-
var s:ansistring; a:integer;begin read(s); val(s[length(s)],a); if odd(a) then write('jishu') else write('oushu');end.
The number of digits you lose does not exceed 2 billion.
Refer to the upstairs, but upstairs doesn't know then without adding a statement? >>>More
In the sound of firecrackers, the spring breeze sends warmth into Tusu - Yuan Ri (Song) Wang Anshi. >>>More
Don't capitalize it, no, it hurts to look at your head.
With Sogou. Go ahead and give it a try.
Super Internet thesaurus, all-encompassing. >>>More