You are currently viewing Best Prime numbers finding solution within a range in 2023

Best Prime numbers finding solution within a range in 2023

How to design code for finding out Prime numbers within a range

For C code learning students are advised to practice few basic codes, prime numbers checking is one of them. Though this code is bit advanced. As this code will check prime number within a range.

In C code practice, prime number plays a very important role. For developing logic, this type of programs are very important. So I have designed this code as easy as possible for the students. They will be able to understand each and every step very easily. 

Before going for this type of program a student should go through basics of loop structure. So that they can easily go through each step with self explanation mode. 

For more code click here. For video tutorial on several topics click here.

This code is for finding out prime numbers within a certain range

#include<stdio.h>

int main()
{
    int p,i,m,j;
    
    printf("Enter the range : ");
    scanf("%d",&m);
    printf("List of Prime Numbers are : ");
    for(j=1;j<=m;j++)
    {
    p=j;
    for(i=2;i<=p/2;i++)
    {
        if(p%i==0)
        break;
    }
    
    if(i>p/2)
    printf("%d  ",p);
    }
    return 0;
}

Leave a Reply