0% found this document useful (0 votes)
3 views1 page

C++ Program to Generate Prime Numbers

This C++ program generates the first N prime numbers. It takes user input N and then uses a for loop to iterate from 1 to N, checking if each number is divisible by any number from 2 to itself/2 using a while loop. Prime numbers are outputted, while non-primes are skipped over.

Uploaded by

Raja Poddar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

C++ Program to Generate Prime Numbers

This C++ program generates the first N prime numbers. It takes user input N and then uses a for loop to iterate from 1 to N, checking if each number is divisible by any number from 2 to itself/2 using a while loop. Prime numbers are outputted, while non-primes are skipped over.

Uploaded by

Raja Poddar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

9.

C++ Programe generate first N prime number

#include(iostream.h)

#include(conio.h)

void main( )

int n, x, flag,ct;

clrscr( );

cout<<"Enter the n value:"; cin>> n;

cout<<"Prime Numbers:";

for( ct=1; ct<=n; ct++)

x=2; flag=0;

while(x<=ct/2)

if(ct%x==0) { flag=1; break; }

x++;

if(flag==0)

cout<< ct;

getch( );

You might also like