Input the lower limit and upper limit and print all prime numbers between them using function.
#include <stdio.h>
#include <conio.h>
int prime ( int );
void main ( )
{
int l, u, i;
clrscr ( );
printf("\n\n\n\n\t\t Enter the lower limit..:"); scanf("%d",&l);
printf("\n\n\t\t Enter the upper limit..:"); scanf("%d",&u);
printf("\n\n\t All Prime numbers between %d and %d are..:\n\n ",l,u);
for ( i = l; i <= u; i++ )
{
if ( prime ( i ) )
{
printf("%d\t",i);
}
}
getch ( );
}
int prime ( int n )
{
int i;
for ( i = 2; i < n; i++ )
{
if (n % i == 0 )
return 0;
}
return 1;
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
int prime ( int );
void main ( )
{
int l, u, i;
clrscr ( );
printf("\n\n\n\n\t\t Enter the lower limit..:"); scanf("%d",&l);
printf("\n\n\t\t Enter the upper limit..:"); scanf("%d",&u);
printf("\n\n\t All Prime numbers between %d and %d are..:\n\n ",l,u);
for ( i = l; i <= u; i++ )
{
if ( prime ( i ) )
{
printf("%d\t",i);
}
}
getch ( );
}
int prime ( int n )
{
int i;
for ( i = 2; i < n; i++ )
{
if (n % i == 0 )
return 0;
}
return 1;
}
Click here to contact us
No comments:
Post a Comment