0

Coding interview questions

Write a Program to check whether a number is prime or not.

16th Nov 2024, 2:42 AM
darius franklin
darius franklin - avatar
2 odpowiedzi
+ 6
Steps:- Suppose the number is user input, now set a loop(either for or while) that runs from 2 to input-number/2 or input-number-1(to avoid 1 as every number is divisible of 1).Define a Boolean variable and set it's value as true as default value and change its value to false if the loop find any number that is divisible of user input.(Note, define the Boolean variable outside the loop).
16th Nov 2024, 9:03 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 1
Show us your work, we'll help you out.
16th Nov 2024, 3:37 AM
Jerry Hobby
Jerry Hobby - avatar