## 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();

}

Categories:PREPARATION MATERIALS;Tags: C, C PROGRAM, C PROGRAM PRIME NUMBER GENERATION, C-PROGRAMMING, PRIME, PRIME NUMBER GENERATION, PRIME NUMBERS

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

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

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

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

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.