0
Can anyone type c program for checking whether the enter no. is prime number or not .
6 Antworten
+ 1
Here's a code I wrote months ago
https://code.sololearn.com/clMqdiMr8Thp/?ref=app
Although it's C++
+ 1
Yahiko why didn't you just use a boolean and only one output based on said boolean
+ 1
Sriram Sekar try to implement below logic on your own... you will definately get it done.. if you face any difficulty, feel free to ask:
you can check whether any number is divisible by anything starting from 2 to number (infact square root of number) or not... if it is divisible, number is not prime.
For example , you want to check number 6 as prime, try to divide it from 2 to 5 and as it's divisible by 2 , it's not prime..
as 7 is not divisible by 2 to 6, it's prime...
note that 1 is not prime number
+ 1
Yahiko , your code does work perfectly... what hinanawi is trying to suggest is code readability and removal of duplicate lines..
you have mentioned cout in each condition... you can set bool IsPrime as true in top and set it to false/true in each if or elseif condition..
At the end of entire logic block of if else, you can do write cout as prime or not based on bool value
+ 1
Alright then
0
Hinanawi I don't understand