Friday, 20 February 2015

Prime numbers program in C in the easiest way – how to Write?

                Here Freshers Junction blog writes Prime numbers Program in C (in Easiest Way). First you need to know what is prime number. After that don’t mug up program know the functionality of program and just remember logic.

What is Prime number:

                Prime numbers means “The Number which is divisible by only 1 or itself ”. The Examples for prime numbers is 13,17,19,23 etc. Here you can notice all these numbers are not divisible by any other number except 1 and itself.

Prime numbers program in C :

 In the below image freshers junction blog clearly writes the Prime numbers program, in That you first concentrate on logic.

To see the Program clearly , click on the following image
Prime-Numbers-program-in-c


1. if (n>=1) – here you can check the entered number (how many prime numberss required – n ) is greater than 1 or not (because prime numbers must be positive number). If ‘n’ is greater than 1 then program continued otherwise “Return 0” statement executed
2. In the Second logic as shown in image printf function is executed (up to here program output is “first 5 prime numberss are 2) . here 5 is a n value, that is In first step entered value.
3. In the third statement for loop is executed for 3 times (3,4,5).  Because count is not greater than 5.(n value is 5)
4. In the fourth step one more for loop is executed, here I value is 3 as we initialized. Now the for loop is executed, next it check (i%c==0) so it is true, then break statement is executed. And then check (c==i) or not. If it is true then I value is printed else count and I values are incremented and program run again.

Finally The output is:


How many Prime numberss are required:
5
First 5 prime numberss are
2
3
5
7
11
Note: You can remember the Program as 5 parts as shown in image. Then it is very easy to remember prime numberss program in C.

Frequently asked Number Series Questions

You may also search in Google as:
How to write prime numbers program in C, prime numbers program using functions in C, C program for prime numbers, find prime numbers in C program, C program to prime numbers, prime numbers program in C, How to find prime numbers in C, easiest Prime numbers program, Simple Prime numbers program.

Freshers, Register Here

share facebook

Enter Your Email below to get Daily Job Alert in Your Mailbox