CODE OF GEEKS


A PLATFORM TO LEARN | CODE | ACHIEVE


" Programming is the real test of your creativity,its all about how you turn ideas into codes. "



Connect :


THIS WEBSITE IS BEST VIEWED IN THE GOOGLE CHROME WEB BROWSER.



TO GENERATE ALL THE PRIME NUMBERS LYING IN THE GIVEN RANGE IN C

Code

#include<stdio.h>
int main()
{
int i,j;
int num=0;
int inran,outran;
int count=0;
printf("ENTER THE INNER RANGE : \n");
scanf("%d",&inran);
printf("ENTER THE OUTER RANGE : \n");
scanf("%d",&outran);
for(i=inran;i<=outran;i++)
{
count=0;	
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
count=1;
}	
}
if(count==0)
{
printf("%d ",i);	
}	
} 
return 0;
}

Output


ENTER THE INNER RANGE : 4
ENTER THE OUTER RANGE : 76
5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73


What we did - Our Approach


In this problem we have to find all the prime numbers between an inner range and an outer range.
****PRIME NUMBER CHECKER****
A prime number is a whole number greater than 1 whose only factors are 1 and itself. A factor is a whole numbers that can be divided evenly into another number. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29.

For checking a prime number,we ran a for loop from i:2 to n/2,now if our number gets divided by any value of 'i' we set our counter to 1. After the end of the loop , if counter=0 then our number is a prime number else not.

Join us :



CODE OF GEEKS

A Platform to LEARN | CODE | ACHIEVE

Connect :



INTERESTING READ FOR YOU :

SHARE:



For any Queries,suggestions,feel free to Mail us at :
codeofgeeks@gmail.com

For reporting any kind of copyright voilation,mail us at : cogcopyclaim@gmail.com

© copyright CODE OF GEEKS 2018