write the 10 prime nos program in c++?



write the 10 prime nos program in c++?..

Answer / Anjani Kumar Sinha

To write a C++ program to find the first ten prime numbers, you can use the following code:```cppn#include <iostream>nusing namespace std;nvoid printPrimes(int n) {n bool isPrime[n + 1]; // boolean array to store if a number is primenfill(isPrime, isPrime + n + 1, true); // init all numbers as primenfor (int p = 2; p * p <= n; ++p) {n for (int i = p * p; i <= n; i += p) {n isPrime[i] = false;n }n}nfor (int p = 2, count = 0; p <= n; ++p) {n if (isPrime[p]) {n cout << p << " ";n ++count;n if (count == 10) return;n }n}n}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Electronics Communications Interview Questions

i am fresher for giving intervivew in it sector and also sales electronics. all about related qustions send me please?

1 Answers  


Name the two forms of boolean expression?

1 Answers  


What are the advantages of gto over scr?

1 Answers  


write a c program to multi(*) of two matrix using pointers?

1 Answers  


In 8086 why even address location takes two bus cycles whereas odd address location takes only one bus cycle??

2 Answers  


what is the source of time varying magnetic field?

2 Answers  


what is the properties of good transformer oil

1 Answers  


Why opamp called direct coupled high differential circuit?

1 Answers  


where you wants to see you after 5 year?

1 Answers   Tech Mahindra,


How to manufacture the cmos inverter?

1 Answers  


can anybody mail the exact sylabuss for ECIL

0 Answers  


Explain digital circuits?

1 Answers  


Categories
  • Civil Engineering Interview Questions Civil Engineering (5086)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4453)
  • Electrical Engineering Interview Questions Electrical Engineering (16638)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)