+ 1

How do i print "it is prime" on the screen whenever a primw number is given? It works well if i enter a composite number

#include <iostream> using namespace std; int main() { int a; cout<<"please enter a number"<<endl; cin>>a; cout<<a<<endl; for(int i =2 ;i<a;i++){ if(a%i==0){ cout<<"it is not prime as it is divisible by "<<i<<endl<<endl; }} return 0; }

4th Jun 2018, 10:24 AM
Vikram
Vikram - avatar
2 odpowiedzi
4th Jun 2018, 10:43 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
You could use it in a function. Let me write a code for you.
4th Jun 2018, 10:34 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar