AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

Checking for prime numbers algorithm - C++

Go down

Checking for prime numbers algorithm - C++

Post by Lucaci Andrei on Mon Mar 12, 2012 10:56 pm

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
* k.cpp
* k.cpp is licensed under GNU GENERAL PUBLIC LICENSE
* Created on: Mar 13, 2012
* Author: sin
*/
#include<iostream>
using namespace std;

int ver_prim(int a){
for (int i=2; i<=a/2; i++)if (a%i==0) return 0;
return 1;
}

int main(){
int a;
for (;;){
cout<<"a= ";
cin>>a;
if (ver_prim(a)==1) cout<<a<<" is prime.\n";
else {cout<<a<<" is not prime.\n";
}
}
return 0;
}

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 25
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum