- Hello World c
- C Program to Add Two Numbers
- Area of Triangle C
- Odd or Even C
- Write a C program to find the sum of digitis of a given number
- Write a C program to find the maximum of three numbers
- Write a C program to swap two number using third variable
- Write a C program to swap to numbers without using third variable
- Write a C program to calculate the area of circle
- Write a C program to calculate the Binomial Coefficient (nCr)
- Write a C program to calculate the permutations (nPr)
- Write a C program to reverse the number
- Write a c program to check the given number is palindrome or not
- Write a c program to check the given number prime or not
- Write a c program to check the given number is armstrong or not
- Write a C program to generate all Armstrong number till n
- Write a program to check given number perfect or not
- Write a C program to check alphabet is vowel or consonant
- Write C program to calculates the factorial of a given number
- Write a C program generate and prints the Fibonacci series up to a user-defined limit
- Write a C program to calculate the nth number in the Fibonacci series using recursion
- Write a C program to find the maximum element in the array
- Write a C program to find the minimum element in the array
- Write a C program to search the element using linear search technique
- Write a C program to Insert element in array

**Prime Number** is a number which divisible by 1 and own so we called the number is prime. The condition is number is greater than 1. A number is divisible by itself or 1 so called the prime number.

```
// Write a c program to check the given number prime or not.
#include<stdio.h>
#include<stdbool.h>
// boolean return type function to isPrime()
bool isPrime(int n){
if(n < 2){
return false;
}
for(int i = 2; i < n; i++){
if(n % i == 0){
return false;
}
}
return true;
}
// main function
int main(){
int n;
printf("Enter the number : ");
scanf("%d", &n)
if(isPrime(n)){
printf("%d is a prime number", n);
}else{
printf("%d is not a prime number", n);
}
return 0;
}
```

`#include<stdio.h>`

This line include the **standard libary** function to used for input/output function in program.

`#include<stdbool.h>`

This line include the statndard library to used for **bool type method/keywords** like true or false and return type also of **boolean function**.

```
// check prime function
bool isPrime(int n){
if(n < 2){
return false
}
for(int i = 2; i < n; i++){
if(n % i == 0){
return false;
}
}
return true;
}
```

Above the function called as **isPrime()** is used for to check the given number is **prime** or not, this function **return type bool** which return only true or false. Inside the function for loop start from 2 to n - 1 because we know about the **prime number** very well that if number is devided 1 or itself then then the number is prime otherwise number is **not prime** so we start the for loop from 2 to n - 1, if n % i == 0 then return false (means given number is not prime) otherwise after complete the loop then return true (means given number is prime). if n < 2 then return false suppose anybody give the input 1 so **1 is not a prime number** the first prime number is 2.

```
// main function
int main(){
int n;
printf("Enter the number : ");
scanf("%d", &n);
if(isPrime(n)){
printf("%d is a prime number", n);
}else{
printf("%d is not a prime number", n);
}
return 0;
}
```

In the main function which known as the **entry point** of the program, declared the variable named n as integer. Prompt to user enter the number and read the input from the user. Check using the **if-else statement**, **if(isPrime(n))** then print "%d is a prime number" otherwise print "is not a prime number" using the printf() function, after this the program **return 0** which indicates that program is successfully executed.

1. Start

2. Declared an variable AS INTEGER

3. Read the input from user

4. Check given number is prime or not

5. isPrime() true then print " %d is a prime number", n

6. otherwise print "%d is not a prime number", n

7. End

```
// Pseudocde of prime number
1. INCLUDE stdio.h
2. INCLUDE stdbool.h
3. FUNCTION isPrime(int n)
1. FOR i = 2 to n - 1
1. IF n % i == 0
RETURN false
2. RETURN true
4. FUNCTION main()
1. DECLARED n AS INTEGER
2. PROMPT to the user enter the number :
3. READ the input and store the value in n variable
4. IF isPrime(n)
PRINT "%d is a prime number", n
3. ELSE
PRINT "%d is not a prime number", n
```

ðŸ–¤ 0

Buy me coffee â˜•

## Comments

Oops!