C PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND N | Indian Shout

You are here: » C PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND N

C PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND N


/* Write a C program to generate all the prime numbers between 1 and n, where n is a value supplied by the user. */

#include <stdio.h>

void main()
{
int no,counter,counter1,check;
clrscr();
printf(“<———————–PRIME NO. SERIES————————>”);
printf(“\n\n\n\t\t\tINPUT THE VALUE OF N: “);
scanf(“%d”,&no);
printf(“\n\nTHE PRIME NO. SERIES B/W 1 TO %d : \n\n”,no);

for(counter = 1; counter <= no; counter++)
{
check = 0;
//THIS LOOP WILL CHECK A NO TO BE PRIME NO. OR NOT.

for(counter1 = counter-1; counter1 > 1 ; counter1–)
if(counter%counter1 == 0)
{
check++;        // INCREMENT CHECK IF NO. IS NOT A PRIME NO.
break;
}
if(check == 0)
printf(“%d\t”,counter);
}
getch();
}

Similar Posts:

 
 
Posted by 4 Responses

Categories:PREPARATION MATERIALS;Tags: , , , , , ,

Free Email Newsletter

Stay Updates with this Blog. Get Free email newsletter updates..

And then confirm your email subcription

   

4 Comments to “C PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND N”

  1. adej says:

    have not really tested your program because i wrote some myself what am so concerned about is the compilation time and the processing time when a user in put large n,don’t know if you have consider that

  2. Vijay says:

    how to check whether a no. can be written in the form of power of 2…..like 32 as 2^5…….8 as 2^3….but 20 cannot

  3. n numbers for get the user that number is how many numbers in the user input for prime numbers

  4. hardip patel says:

    I have my self-invented program to calculate Armstrong numbers from 1 to n,where is n is our wish provided n<2000000000.
    So Email me to get it free,
    my Email is ham_rock_star@hotmail.com.

Leave your comment here:

 
Sponsored links
Free Email Updates
Get All Latest Updates in Ur e-mail Inbox..

And then confirm your email subcription

Sponsored Links