Computer Science, asked by prathm2281, 7 months ago

Regina is incharge of the annual day committee. The annual day committee decides to conduct a lucky draw for the audience. As the crowd is huge, it is very hard to include the whole audience in the lucky draw. Therefore, management decides to conduct lucky draw only for the audience who have occupied the chair number which is prime. Regina and other committee members find it difficult to check which chair numbers are prime. Can you help them to find out whether the chair number is prime or not?
Prime number is a number which can be divided only by 1 and itself.

Answers

Answered by sravani53215
13

#include <iostream>

using namespace std;

int main()

{

int n, i, m=0, flag=0;

cin >> n;

m=n/2;

for(i = 2; i <= m; i++)

{

if(n % i == 0)

{

cout<<"Not eligible"<<endl;

flag=1;

break;

}

}

if (flag==0)

cout << "Eligible"<<endl;

return 0;

}

Answered by ankhidassarma9
0

Answer:

#include <iostream>  

using namespace std;  

int main()  

{  

 int n, i, m=0, flag=0;  

 cout << "Enter the Chair number to check Prime: ";  

 cin >> n;  

// 1 is a prime number

if (n == 1)

{

flag = 0;

 }

 m=n/2;  

// If the number is divided by any  number (other than 1 and the number

//  itself)  then it's not a prime number

 for(i = 2; i <= m; i++)  

 {  

     if(n % i == 0)  

     {  

         cout<<"Chair number is not Prime."<<endl;  

         flag=1;  

         break;  

     }  

 }  

 if (flag==0)  

     cout << "Chair number is Prime."<<endl;  

 return 0;  

}  

Explanation:

Input : 17

Output : Chair number is Prime.

Input : 16

Output : Chair number is not Prime.

  • The above C++ program will talk an input number and will check whether it's a Prime number or not.
  • A positive integer that is  divisible by 1 and the number itself is known as prime number.

Similar questions