Friday, 11 August 2017

Prime number in given range

Q : Write a program to display all the prime numbers between two positive integers m and n. The values of m and n are to be taken from the user.

Solution : 


#include<stdio.h>
void main()
{
     int n,m,p;
     printf("Enter range starting number>> ");
     scanf("%d",&m);

     printf("Enter range ending number>> ");
     scanf("%d",&n);
     if(m>n)
           printf("\n\tRange start should be less than range end");
     else
     {
           while(m<=n)
           {
                p=2;
                while(p<m)
                {
                      if(m%p==0)
                           break;
                      p++;

                }
                if(p==m)
                      printf("\t%d",p);
                m++;
           }
     }
}


Download Source Code