C / C++ Program to Print First 30 Prime Numbers


CELEBRATING :: BuildNextWeb's 100th post and first 1 Lacs viewers  
Here we start with a new topic to buildnextweb, Introducing C and C++ programing to buildnextweb. Contributors of Buildnextweb will now posting Basic to advance programs of C and C++. 
In this article we will be dealing with a simple program to print first 30 prime numbers using C / C++.

Here is the code snippets :


#include <iostream>
#include <conio.h>
using namespace std;
int IsPrime(int a){
int p = 1;
for (int i = 2; i < a; i++){
if (a%i == 0){
p = 0;
}
}
return p;
}
int main()
{
int counted = 1, c, i=1;
while ( counted !=30)
{
c = IsPrime(i);
if (c == 1){
cout << i << endl;
counted++;
}
c = 0;
i++;
}
cin >> c;
}
Output of the program : 


Thankuh so much.
  

Share this:

ABOUT THE AUTHOR

Hello We are OddThemes, Our name came from the fact that we are UNIQUE. We specialize in designing premium looking fully customizable highly responsive blogger templates. We at OddThemes do carry a philosophy that: Nothing Is Impossible

0 comments:

Post a Comment