c Write a console program that asks the user to enter an int
c++
Write a console program that asks the user to enter an integer greater than 1. The program determines if the number entered is prime and writes a message to standard output stream stating whether the number is prime or not. For example, if the user enters 42, the program displays \"42 is not prime.\" If the user enters 47, the program displays \"47 is prime.\"
Develop 8 test cases and verify that your program runs correctly for them. The test cases should contain some prime numbers as well as non-prime values. Include test cases that try to break your program so that you are sure you have implemented the code correctly. Include the 8 test cases within a multi-line comment near the top of your source code file. Make sure the comment is nicely organized and easy to read and understand. Here is an example:
/* n result
--- ------------
2 prime
3 prime
4 not prime
...
*/
Solution
Hi inform me if you need any help
================================
code
//test cases 2 47 101 33 99 111 1001 4333
#include<iostream>
using namespace std;
int main(){
int i,j,number;
cout<<\"Please enter number greater than 1:\";
cin>>number;
for(i=2;i<number;i++)
{
if(number%i==0){
cout<<number <<\" is not prime\";
break;}
}
if(i==number)
cout<<number<<\" is prime\";
}
=========================================
explaination:
A Prime Number can be divided evenly only by 1, or itself.
so we are using below code to check this property
for(i=2;i<number;i++)
{
if(number%i==0){
cout<<number <<\" is not prime\";
break;}
}
% is known as modulo operation, modulo operation gives us remainder
as for example 10%3 = 1
so if a number is evenly divisble by a number there % operation will give zero.
so what we did in the code is for the specific number from 2 to that number we are checking if any number divides the given number or not. i.e % is zero or not, if % is zero not a prime otherwise a prime number.
Thanks

