Friday, November 25, 2011

Determine prime numbers

[sourcecode language="cpp"]

#include <iostream>

using namespace std;
int main()
{
int num=0;
int count=0;
int prime=1;
char ans=' ';
do
{
cout <<"Enter a number:  ";
cin >> num;
for (int i=(num)/2; i>1; i--)
{
if (num%i==0)
{
count=count+1;
if (count==1)
cout <<"Internal Factor(s):  ";
prime=0;
cout <<i<<" ";
}
}
if (prime==0)
{
cout<<"\nNumber is not prime."<<endl;
}
if (prime==1)
{
cout <<"Number is prime."<<endl;
}
cout<<"Do you wish to find another prime:  ";
cin>>ans;
cin.ignore(200,'\n');
count=0;
prime=1;
system("cls");
}while(ans =='y' || ans=='Y');
system("pause");
return 0;
}

[/sourcecode]

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...