(C++) CPP Programs - 11

Friday, December 14, 2007

11. Write a C program to generate and print prime numbers in a given range. Also print the number of prime numbers.

/*Print prime numbers in a given range*/

#include

#include

void main()

{

int i,j,m,n,found,count=0;

clrscr();

printf("Enter the lower range and upper range\n\a");

scanf("%d%d",&m,&n);

printf("List of the numbers in the given range\n\a");

for(i=m;i<=n;i++)

{

found=1;

for(j=2;j<=i/2;j++)

{

if(i%j==0)

{

found=0;

break;

}

}

if(found==1)

{

printf("%d\n",i);

count++;

}

}

printf("Total prime numbers between %d and %d=%d\n\a",m,n,count);

getch();

}

0 comments:

Post a Comment

Chitika

About This Blog

Followers

Blog Archive

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP