+ 2

Can someone please write a code for prime numbers using flag?

26th Aug 2017, 5:00 AM
Kirti
Kirti - avatar
6 odpowiedzi
+ 6
#include <iostream> using namespace std; int main() { int n, i, flag; flag = 1; cout << "Enter a positive integer: "; cin >> n; for(i = 2; i <= n / 2; ++i) { if(n % i == 0) { flag = 0; break; } } if (flag==1) cout << "This is a prime number"; else cout << "This is not a prime number"; return 0; }
26th Aug 2017, 5:09 AM
Ankit Saxena
Ankit Saxena - avatar
+ 4
#include<iostream> using namespace std; int main() {     int number,count=0;     cout<<"Enter number to check its Prime or Not : ";     cin>>number;       for(int a=1;a<=number;a++)         if(number%a==0)             count++;       if(count==2)         cout<<"Its Prime Number \n";     else         cout<<"Its not a Prime Number\n";       return 0; } just go through the course here you will learn more and just code and practice 😊
26th Aug 2017, 5:06 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
Thank you Ankit Thank you Gawen
26th Aug 2017, 6:22 AM
Kirti
Kirti - avatar
+ 1
.
19th Sep 2017, 1:37 PM
Madiyar Abdukhashimov_kz_Iut
Madiyar Abdukhashimov_kz_Iut - avatar
0
1000
20th Sep 2017, 2:45 PM
Madiyar Abdukhashimov_kz_Iut
Madiyar Abdukhashimov_kz_Iut - avatar