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

Prime numbers in range - C++ algorithm

Go down

Prime numbers in range - C++ algorithm

Post by Lucaci Andrei on Thu Mar 08, 2012 10:34 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
#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,b;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
for (int i=a; i<=b; i++){
if (ver_prim(i)==1) { cout<<i<<" ";}}
cout<<endl;
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