#include<iostream>
#include<conio.h>
using namespace std;
char
prime_number(int number);
int main()
{
int counter = 0;
char result;
cout << "\n\n\t\t
___ Prime numbers between 1 to 50 ____\n\n\n\n
Prime Number - \n\n ";
for(counter = 1; counter <=
50; counter++)
{
result = prime_number(counter);
if (result == 'Y')
{
cout << counter << " , ";
}
}
cout << "\b\b ";
getch();
return 0;
}
char
prime_number(int number)
{
int counter = 1, count = 0;
while(counter < number)
{
if ((number % counter) ==
0)
{
count++;
}
counter++;
}
if (count == 1)
{
return 'Y';
}
else
{
return 'N';
}
}
No comments:
Post a Comment