**Prime Numbers**

A prime number is an integer greater than 1 that has exactly two divisors, 1 and itself.

The first ten prime numbers are

- 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29.

Integers that are not prime are called composite numbers.

**C program to find prime numbers in a given range**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/** C program to find prime numbers in a given range by codebind.com */ #include<stdio.h> #include<conio.h> int main() { int num,i,count,n; printf("Enter max range: "); scanf("%d",&n); for(num = 1;num<=n;num++){ count = 0; for(i=2;i<=num/2;i++){ if(num%i==0){ count++; break; } } if(count==0 && num!= 1) printf("%d ",num); } return 0; } /* OUTPUT: Enter max range: 30 2 3 5 7 11 13 17 19 23 29 */ |

**C Program to Check If the number is Prime or not**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/** C Program to Check If the number is Prime or not by codebind.com */ #include<stdio.h> #include<conio.h> #include <iostream> using namespace std; int main() { int i,number; printf("Enter any num: "); scanf("%d", &number); if(number == 1) { printf("Smallest prime num is 2"); } for(i=2;i<number;i++) { if(number%i == 0) { printf("Not prime number"); break; } } if(number == i) { printf("Yes, Number is Prime"); } return 0; } /* OUTPUT: Enter any num: 17 Yes, Number is Prime */ |