In this tutorial, we are going to write a program in C to print the first N Prime Number. Basically, on the basis of the given input, our program will print the Prime Number.

For example, if we want to print the first 5 prime numbers, Our program will take 5 as an input and it will print 2,3,5,7,11 as an output.

## What is Prime number?

A prime number is a number that can only divide by 1 and the number itself.

for example, 2, 3, 5 etc are the prime number. Here 2 and 3 can only be divided by 1 and number itself.

But 4 or 6 is not a prime number because 4 can be divided by 2 and 6 can be divided by 2 and 3.

Let’s see the program in C

## C Program to Print first n Prime Number

```
#include<stdio.h>
void main() {
int i = 0, n, temp, temp1 = 1;
printf("Please give input a number: ");
scanf("%d",&n);
printf("Prime numbers Upto %d are \n",n);
while (temp1<=n) {
temp = 0;
for (i=2;i<=(temp1/2); i++) {
if (temp1%i==0) {
temp = 1;
break;
}
}
if (temp == 0)
printf("%d \n",temp1);
temp1++;
}
}
```

**Output**

```
Please give input a number: 26
Prime numbers Upto 26 are
1
2
3
5
7
11
13
17
19
23
```

[wpusb]

## Also Prepare Below Important Question

- Sum of digits of Given Number in Java
- Hibernate Interview Questions for 2+ years of experience
- 68 Most Important Microservices Interview Questions
- 60 Most Important Git Interview Questions
- 50+ Mostly asked Java Interview Questions for 6 Years Exp.
- 60+ Mostly Asked Java Interview Questions for 4 Years Exp
- 60+ Mostly asked Java Interview Question for 3+ Years
- 60+ Spring Boot interview questions for 4+ years Exp.
- 60+ Mostly Asked Spring Boot Interview Questions for 3+ Yrs
- Scenario Based Java 8 Coding Interview Questions (For Experienced)
- Python Program to add two numbers without addition operator
- Mostly Asked Java Interview Questions For 2 Yrs Experience
- Find All Pairs in Array whose Sum is Equal to given number Using Java
- Java Program to find GCD of two Numbers using Recursion
- Python Program to Separate Characters in a Given String
- Python Program to add two number using Recursion
- Python Program to Find Highest Frequency Element in Array
- Python Program to Merge two Arrays
- Perform left rotation by two positions in Array Using Python
- Python Program to Delete Element at Given Index in Array

## Interview Questions Categories

### C Programming Interview Preparation

### Core Java Programming Interview Preparation

- Core Java Programming Coding Questions
- Core Java Pattern Programming Questions
- Core Java Programming Interview Questions