adspace


write the 10 prime nos program in c++?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

i need recent placement paper

1946


sir i need a few nots of electronics component cicuit plz send me some nots

1927


Dear All,I have RRB exam on 19th dec Plz send me the Last 5 years RRB Q&A of Electronics & communication Dept to mail id sham28sharieff@gmail.com.. please frnds if u do have the Q&A.. Plz send it..

2718


send me jto(telecom) exam papers

2068


Hi i am chinna reddy i had completed my b.tech(ECE)2010 passout. but still no job please if anyone help me and suggest me. my mailid:chinnareddy.be@gmail.com Thanks&Regards chinna

2119


Please, give me the simple circuit dig. for "oscillator with variable frequency & upto 6W". I will be very thankful to you.

2043


Draw the equivalent circuit of triac and diac.

1153


please send me last year question for executive tranees in ntpc on my email ID rajthakur2091@gmail.com

2252


I am a fresher and i have done testing course from orbit institute hyd.can any1 say me whether it is necessary to do project in testing.if it is that which is best institute in hyd.can you please inform me if there is any job 4 freshers.thanxs

2003


i want the aptitude test papers of wipro can any one help plz

2014


Please give the model or previous year question paper for the lecture post in government Engineering College (Electronics and Communication)

1878


sir plz send me BPCL recruitment(Engineering Trainee Electronics & Communication) sample question papers & Topics as early as possible

4700


hello sir, could u plz send me a sample placement paper for hpcl trainee engg exam..(electronics stream)...hoping to hear from u at the earliest. Thanking you.

1981


i want to know the syllabus for management trainee exam,vizag steel plant,2009

3571


Any idea of BSNL, JTO paper?

2142