While loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

While loop

2. Write a program to test wither the entered number is a prime number or not using the prime number dived only on 1 and itself.

7th Dec 2017, 7:49 PM
Reema Jarar
Reema Jarar - avatar
1 Answer
0
#include<iostream> using namespace std; int main(){ int n , i ; bool ok=true; for(i=2;i<n;i++){ if(n%i==0){ ok=false; } } if(ok==true){ cout<<"prime"; }else{ cout<<"non prime"; } }
7th Dec 2017, 8:05 PM
Sergiu Ceică
Sergiu Ceică - avatar