C language trip only for loop break seeking the maximum number (prime number) prime

Ⅰ, seeking the maximum number (prime number) for loop and prime BREAK:
①, can be run directly off of code //
#include <stdio.h>
int main ()
{
int J, n-, A =. 1;
the printf ( "Please INPUT ! the Number of n-\ n-");
Scanf ("% D ", & n-);
for (; n-> 0; N-)
{
for (J = 2; J <n-; J ++) // problem arises no taking into account how a number of processing each time and finally taken to the maximum value of n-1, if the look is a prime number;
{// for each object of the cycle is about to find whether the n-1 is a prime number;
iF (n- % j0)
break;
if(j
n-1)
{
printf(“the maximal prime number:%d\n”,n);
a=0;
break;
}
}
if(a==0)
break;
}
return 0;
}

/*for(i=n-1;i>0;n–)
{
for(j=2;j<i;j++)
{
if(i%j==0)
{
a=1;
break;
}
}
if(a=0)
{
printf(“the maximal prime number:%d\n”,j);
}

}
*/

②, the results show:
For example: This program is designed to determine an input value n: i.e., 2 to the largest prime number n; for example when the input is 15, which is the largest prime number is 13, the following results:
Here Insert Picture Description
☺ Message:
Ⅰ, the program running on the Visual C ++ version 6.0;
ⅱ, if I give the procedure in question, or there is a problem in terms of narrative, I can not read or explain the meaning, please leave a message and I pointed out or discussed, thank you big brother ! ! !
Ⅲ,
(1) What is a prime number? Prime refers to his own in addition to 1 and no other divisor, for example: 7, it is only divisible by 1 and itself 7, it is a prime number; and 9 is not a prime number, because in addition to its own 9 and 1 can divisible by 3; is well known, is the smallest prime number 2, neither a prime nor composite;
(2) the procedures for the use of three cycles and determines if several statements:
①, first for loop (; n> 0; n-) , can be used before the first semicolon can be empty, representing nothing;
②, significance of a for loop is: n is from start to find the largest prime number, cycle is the range. 1 ~ n-;
③, the second for loop from j = 2, has been increasing, until j = n-1, it is sufficient that n% j0 holds, it is not a prime number as described, then the break out of the second loop, a for loop is executed first, to the value (that is, n-1) of a n;
④, when in the second for loop , can not n% j
0 holds, and satisfies j == n-1, to find the largest prime number, such that a flag is 0, can jump out first for loop, may be out of the second for loop;
effect ⑤, break out of the cycle is labeled ; and a role is a sign that there is no other meaning;

Published 40 original articles · won praise 0 · Views 598

Guess you like

Origin blog.csdn.net/weixin_43405300/article/details/103865769