+ 2

What the mistaks in this code to print the prime numbers .. And give me the true one ..thank you

#include <iostream.h> int main() { int n,s,p; cout<< "enter number"; cin>>p; for(n=1;n<=p;n++) { if (p%n!=0) { s=1 break ; cout <<"not prime"; } else { s=0 } } if(s==0) cout <<"prime"; return 0; }

19th Nov 2017, 5:31 AM
Aliaa Queen
Aliaa Queen - avatar
18 Respostas
0
sure I have the solution to this
19th Nov 2017, 5:52 AM
Abubakar Hussain
Abubakar Hussain - avatar
+ 4
No need for the using namespace std?and the break might be a mistake I think...
19th Nov 2017, 6:12 AM
Stephanie
Stephanie - avatar
+ 4
The code will never print because before printing anything you break out of the loop
19th Nov 2017, 8:39 AM
ishan kotnala
ishan kotnala - avatar
+ 3
I guess the code cannot run...
19th Nov 2017, 6:15 AM
Stephanie
Stephanie - avatar
+ 1
where can I send you a pic of the code
19th Nov 2017, 5:56 AM
Abubakar Hussain
Abubakar Hussain - avatar
+ 1
if(p%n ==0) print not prime number else (p%n !=0) print prime number
19th Nov 2017, 6:03 AM
Abubakar Hussain
Abubakar Hussain - avatar
+ 1
just be simple your complicating things
19th Nov 2017, 6:06 AM
Abubakar Hussain
Abubakar Hussain - avatar
+ 1
how we can modefid it? 💔
19th Nov 2017, 6:17 AM
Aliaa Queen
Aliaa Queen - avatar
+ 1
🐸🐸
19th Nov 2017, 6:40 AM
Aliaa Queen
Aliaa Queen - avatar
0
يا ريت تكتبلي التعديلات و مشكور
19th Nov 2017, 5:55 AM
Aliaa Queen
Aliaa Queen - avatar
0
I don't understand Arabic too
19th Nov 2017, 5:56 AM
Abubakar Hussain
Abubakar Hussain - avatar
0
اعمل كوبي بيست هون اذا بصير
19th Nov 2017, 5:57 AM
Aliaa Queen
Aliaa Queen - avatar
0
😂😂😂😂😂 write here if you can
19th Nov 2017, 5:59 AM
Aliaa Queen
Aliaa Queen - avatar
0
we need to fix all numbers below the the fixed number so if statement dont enough ..is not??
19th Nov 2017, 6:10 AM
Aliaa Queen
Aliaa Queen - avatar
0
well I didn't understand your question? you want to check if a number is prime or not?
19th Nov 2017, 6:14 AM
Abubakar Hussain
Abubakar Hussain - avatar
0
yes
19th Nov 2017, 6:15 AM
Aliaa Queen
Aliaa Queen - avatar
0
We can
19th Nov 2017, 6:23 AM
Abubakar Hussain
Abubakar Hussain - avatar
0
but break in if statment not for all program
20th Nov 2017, 4:57 AM
Aliaa Queen
Aliaa Queen - avatar