Join WhatsApp Channel Join Now
Join WhatsApp Group Join Now
Telegram Channel Join Now
Showing posts with label Programs. Show all posts
Showing posts with label Programs. Show all posts

Monday, 16 March 2015

Write A Program To How To Find Whether Given Number Is Prime Number Or Not - in Easiest Way

In Last article Freshers Junction explain “How to write a Prime Number Program”. In that article freshers junction clearly explained What is prime number, how to write prime number program in easiest way. Now in this article Freshers Junction blog explain Prime Number program to check whether it is prime or not in the Easiest Way. These Both questions are frequently asked question in Technical Interview. And also you can remember these two prime numbers are basic C programs, you should know these walkins before attending Interview.

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 Number program to check whether it is prime or not

In the above program, we initially initialize C as integer 2.
After This Printf Prints a “Enter a number to check if it is prime” line
Scanf function reads the Input n value from user.
Now here we are using for loop, here we check the given number is prime number or not

Example: if the input from user is 15. Then initially 15 is divided by 2 (because we initialize C Value as 2) if the result is 0 then the given number is not prime. But 15/2 is 1, now the loop is again executed. Now C value is incremented by 1 (Due to c++). So now 15/3 is checked. This time result is 0. So the Given number is Not a Prime Number.


Conclusion: If you have any queries about prime numbers program, comment here. We provide best solution to your questions.

Note: “Difference Between Method Overloading and Method Overriding in .Net/ JAVA” is also one most important question for Technical Interview.

Use Ctrl+D to bookmark this page to see whenever you want

You Can Search in Google also like:
How to find given number is Prime Number or not. Prime Numbers program in C, easiest Prime number program, check given number prime or not, All types of Prime Numbers program, prime number program using single for loop. How to find whether given number is prime number or not easiest way.

Saturday, 21 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.