-
You can add a 0 to the end of the array, but you can't have a 0 in the middle. Then change it to something like this:
#include
int main()
int n, i,k, a=;There is an extra 0n=0; Assign an initial value of 0 to n
while(a[n]) When a[n] is true, i.e. a[n] is not 0
k=sqrt(a[n]);Here we use a[n]for(i=2; i<=k;i++)
if(n%i==0)break;
if(i>k)
printf("%d ",n);
n++;n is incremented by 1 so that a[n] is the next number.
-
The program is not very well written.
First of all, how can you use your printf without include.
Secondly, the return value of the main() function is int, but you don't have a return.
Again, what does n=a mean, I haven't seen k is int, but the return value of sqrt() is double.
Finally, the for loop seems to only be able to judge one number, if it could.
-
lz has learned arrays, and he can still write such a bad program, which is admired!
After all, men become big things. Laying a good foundation is key!
Don't forget!
-
#include ""
void main()
If an integer is prime, then only it is divisible by 1 and itself, so there is only 2, and if it exceeds 2, then it is certainly not prime.
if (flag==2) else}
-
#include
#include
#include
int prime(int a) defines a function to determine whether a is prime or not
if (flag==2)
return 1;*If a is a prime number, the flag should be 2 and the return value is 1*
elsereturn 0;*If a is not prime, the flag is greater than 2 and the return value is 0*
* (This part is supplemental, the prime function can be simplified to :)int prime(int a).)
return flag;}*/
int main()
-
For details, please refer to:
Prime numbers areOnlyA positive integer divisible by 1 and itself. For example, 2 is a prime number: 2 1=2, 2 2=1, i.e., 2 is divisible by 1 and is 2, and 2 is divisible by 1 and itself, so it is a qualitative curved number.
This is an additive function I wrote that can judge overflow: >>>More
Indicates that the remainder of 6 is taken.
In the C language, % stands for remainder (or modulo operation). >>>More
Valid variable names for the C language:
First, it can only contain numbers, letters, and underscores. >>>More
It seems that you don't know much about structs and struct pointers, the data array is a struct array that you define, it consists of two knot body elements, and each struct element contains two members x and y, the first element is 1 and 10, the second element is 2 and 20, the struct pointer p you defined starts to point to the first element of the array data, p points to the second element of the data array, and the pointer p can manipulate the two members x and y >>>More
The semicolon is the sign of the end of the statement, but the semicolon is not used after the loop, if, and subfunctions such as long long a (int b), and everything else is used, but two semicolons cannot be added, although it will not cause an error, but it may affect the result.