In this tutorial, we will learn to write the C Program to print Prime Number in a given range.
Let’s see what is our problem statement which we will solve in this tutorial.
We will take the range in the form of an integer. After taking the input we will then find all the prime numbers existing in the given range.
For Example:
The input we have taken 3 and 15
So, the output will be 5, 7, 11 and13. Because these are the only numbers that are prime between the range 3 and 15.
How our program will behave
- Our Program will take two integer numbers as an input to find the find the prime numbers.
- Now we will use while loop start from first integer till smaller than the second input. This is because we only want in between two.
- We will pick every time one number and will check it is divisible by any number other than 1.
- If it is divisible then it is not a prime number. Otherwise our program will print that number as Prime number.
C Program to print Prime Number in a given range
#include<stdio.h> void main(){ int i=0,fNum,sNum, temp,temp1=1; printf("C Program to Print Prime number in a given range\n"); printf("Please give the first number: "); scanf("%d",&fNum); printf("Please give the second number: "); scanf("%d",&sNum); while(fNum<=sNum){ temp=0; for(i=2;i<=(fNum/2);i++){ if(fNum%i==0) { temp=1; break; } } if(temp==0) printf("%d is a prime number \n",fNum); fNum++; } }
Output

Share on
Also Prepare Below Important Question
- Java Program to Perform Left Rotation on Array Elements by Two
- Java Program to Perform Right Rotation on Array Elements by Two
- Java Program to Print Odd Numbers from Array
- Java Program to Print All Even Numbers in Array
- Java Program to Find the Sum of Array Elements
- Java Program to Delete Element of Array At Given Location
- Java Program to Delete a given Element of Array
- Java Program to Delete Element at End of Array
- Java Program to Insert Element in Array at given Location
- Java Program to Insert Element At the End of Array
- Java Program to Print Length of an Array
- Reverse Array without using Second Array or inplace Reversal Java Program
- Java Program to Print Array in Reverse Order
- Java Program to Sort String Character in Descending order
- Java Program to Sort String in Ascending Order
- Java Program to Print non Repeating Characters in String
- Java Program to Find Sum of Integers in the String
- Java Program to Remove Duplicates From String
- Java Program to Concatenate two Strings
- Java Program to Check if two Strings are Same
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