Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n,v[1000],y;
- bool prim(int x)
- {
- if (x<2){
- return false;
- }
- if (x%2==0&&x!=2){
- return false;
- }
- for (int i=3;i*i<=x;i+=2){
- if (x%i==0){
- return false;
- }
- }
- return true;
- }
- void cerintaUnu()
- {
- for (int i=0;i<n;i++){
- if (prim(v[i])){
- cout<<v[i]<<' '<<i+1<<endl;
- }
- }
- }
- int Euclid(int a,int b)
- {
- int c;
- while (b!=0){
- c=a%b;
- a=b;
- b=c;
- }
- return a;
- }
- void cerintaDoi()
- {
- int DC=Euclid(v[0],v[1]);
- for (int i=2;i<n;i++){
- DC=Euclid(DC,v[i]);
- }
- cout<<"2. "<<DC<<endl;
- }
- void afisare()
- {
- for (int i=0;i<n;i++){
- cout<<v[i]<<' ';
- }
- cout<<endl;
- }
- void cerintaTrei()
- {
- int i, j;
- for (i = 0; i < n-1; i++){
- for (j = 0; j < n-i-1; j++){
- if (v[j] > v[j+1]){
- swap(v[j] , v[j+1]);
- }
- }
- }
- afisare();
- }
- void cerintaPatru()
- {
- int st=0,dr=n,poz=-1,m;
- while (st<dr&&poz==-1){
- m=(st+dr)/2;
- if (v[m]==y){
- poz=y;
- }else{
- if (v[m]<y){
- st=m;
- }else{
- dr=m;
- }
- }
- }
- if (poz==-1){
- cout<<"NU S-A GASIT";
- }else{
- cout<<"ELEMENT GASIT PE POZITIA A "<<poz<<"-A";
- }
- }
- void citire()
- {
- cin>>n;
- for (int i=0;i<n;i++){
- cin>>v[i];
- }
- }
- int main() {
- citire();
- cerintaUnu();
- cerintaDoi();
- cerintaTrei();
- cout<<"ELEMENTUL CARE TREBUIE CAUTAT ESTE: ";
- cin>>y;
- cerintaPatru();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement