C Programming
Computer Programming

C Program using function to Display all prime numbers between two Intervals



Write a Program in C using function to Display all prime numbers between two Intervals

\* C Program using function to Display all prime numbers between two Intervals *\

# include < stdio.h >
# include < conio.h >
int   prime(int) ;

int   main( )
{

int m, n, i , k ;
printf(" Enter the begning of interval : ") ;
scanf("%d", &m) ;
printf(" Enter the end of interval : ") ;
scanf("%d", &n) ;

i = m ;
while( i <= n )
{
    k = 0 ;
    k = prime(i) ;
    if( k==0 )
    {
        printf("\t%d", i) ;
    }
    i = i + 1 ;
}
return (0) ;

}

int   prime(int num)
{

int s = 0, i ;
for ( i = 2; i < num ; i++ )
{
    if( num % i == 0)
    {
        s = s + 1 ;
    }
}
return (s) ;

}

Output of Program :

Output of C Program using function to Display all prime numbers between two Intervals