#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();//clearing the screen
int n,x=2,count=0;//Here count is initialised to 0,if it is not prime it remains the same,else it will be equal to 1.You will understand this as you go down
//A number is a prime number if it is not divisible by any other number from 2 and the number before it.
printf("Enter a number : ");
scanf("%d",&n);
while(x<n)//As this checking process should continue till the number just preceding it
{
if(n%x==0)//checking if the number n is divisible by x or not
{
count++;//IF divisible,there is no meaning in continuing,So we are coming out of the loop by incrementing the variable "count"
break;
}
else
x++;
}
if(count==0)
{
printf("%d is a prime number",n);
return 0;//Here if number is prime,There is no need to go further and execute till end,To reduce time complexity ,We will write a return statement to stop executing the code.
}
printf("%d is not a prime number",n);
return 0;
}
Diese Zeilen nichts zu tun: 'n> 1;' und 'a = n &&n SurvivalMachine
Haben Sie nicht vergessen, sagen Sie, eine Schleife in dort? 'n' und' x' sind nicht einmal initialisiert. Informieren Sie sich über 'for'-Schleifen und, naja, über grundlegende C im Allgemeinen. Dein Code macht absolut keinen Sinn, obwohl ich denke, dass du irgendeine Art von Schleife willst, aber nicht weißt wie oder was. Mit anderen Worten: ** lerne zuerst ein paar grundlegende C **. –