# C program to check number is prime number or not

### Solution : Without using function(Using for loop) Program/Source Code

```#include <stdio.h>

int main()
{
int n,i,z=0;
printf("Enter any no ");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
z=1;
break;
}
}
if(z==0)
printf("Number is prime");
else
printf("Number is not prime");

return 0;
}
```

Output:

case 1:
Enter any no 25
Number is not prime

case 2:
Enter any no 3
Number is prime

# C program to check number is prime number or not

### Solution : Without using function(Using while loop) Program/Source Code

```#include <stdio.h>

int main()
{
int n,i,z=0;
printf("Enter any no ");
scanf("%d",&n);
i=2;
while(i<n)
{
if(n%i==0)
{
z=1;
break;
}
i++;
}
if(z==0)
printf("Number is prime");
else
printf("Number is not prime");

return 0;
}
```

Output:

Enter any no 26
Number is not prime

Enter any no 17
Number is prime

# C program to check number is prime number or not

### Solution : Using function Without Passing Arguments Program/Source Code

```#include <stdio.h>
/* function definition */
void prime()
{
int n,i,z=0;
printf("Enter any no ");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i==0)
{
z=1;
break;
}
}
if(z==0)
printf("Number is prime");
else
printf("Number is not prime");

}
int main()
{
prime(); /* function calling */

return 0;
}
```

Output:

case 1:
Enter any no 36
Number is not prime

case 2:
Enter any no 53
Number is prime

# C program to check number is prime number or not

### Solution : Using function By Passing Arguments Program/Source Code

```#include <stdio.h>
/* function definition */
void prime(int n)
{
int i,z=0;
for(i=2;i<n;i++)
{
if(n%i==0)
{
z=1;
break;
}
}
if(z==0)
printf("Number is prime");
else
printf("Number is not prime");

}
int main()
{
int n;
printf("Enter any no ");
scanf("%d",&n);
prime(n); /* function calling */

return 0;
}
```

Output:

case 1:
Enter any no 125
Number is not prime

case 2:
Enter any no 197
Number is prime

## Next: C program to print all prime numbers from 1 to 100

### Interview Questions

C Programming
C++ Programming
Class 11 (Python)
Class 12 (Python)
C Language
C++ Programming
Python

C Interview Questions
C++ Interview Questions
C Programs
C++ Programs

Important Pages