how to write a CPP program to check the prime number. and how can we solve this prime number program? In this post, we explain how to check the prime number program. Knowledge of CPP is necessary to understand this program.
what is a prime number?
The prime number is that. Which is divisible by 1 and is divisible by itself and apart from that, is not divisible by anyone else. We are only talking about positive integer here.
Click on this prime number for more details.
solving approach is that.
First of all, you can imagine the output screen then build your logic.
Enter a number: 1717 is a prime numberEnter a number: 66 is not a prime number
You must have this knowledge
Program Logic
You have to declare three variables. int type i, fresh=0, prime
Now take the input in the step named prime.
Apply the loop condition, initialize i=2 in the loop condition Then you should continue the loop. Until i is equal to prime.
We will put an if condition inside the body of the loop. And this time the value of fresh is 1. if condition is true. So it means that not a prime number. If not true. So the if condition will not work. And will reach the endpoint of the loop. Then the value of i will be incremented. And the loop will run again.
the loop will run repeatedly. Until the value of i is equal to the prime variable. And then when the value of i is equal to the prime variable. then the condition of the loop will be false.
now, cursor move on the next statement.
Now the if condition outside the loop will be checked.
After this, if the prime variable is equal to i-1. Still not that prime number. And if not equal i-1. So that number is a prime number.This is another method. To check the prime number programming in c.
source code prime number programming in c
c program fibonacci series using recursion
c program for multiplication of two matrices
find greater number between three
😊
Now next you are, write your code in the comment below.😊
0 Comments:
Post a Comment
Please do not enter any spam link in the comment box.