domingo, 14 de julio de 2013

ARREGLO DE VECTORES CON FUNCIONES

//MULTIPLES EJERCIICOS DE ARREGLOS(VECTORES) EN C++
#include<iostream>
#include<math.h>
#include<conio.h>
    float ordenacion_burbuja(int,int,int,int,float,float);
    float cantidaddeelementos_deAenB(int,int,int,int,int,int,int,int);
    float cantidadde_numerosprimos(int,int,int,int,int);
    int n[4],a[4],b[4],z[5];
    int x,tmp,i,j,LI,LS,c=0,d;
    bool flag;
    using namespace std;
    int main () {
    do{
    cout<<"1.ordenar 4 numeros por metodo de burbuja"<<endl;
    cout<<"2.¿cuantos elementos de A se encuentran en B?"<<endl;
    cout<<"3.hallar la cantidad de numeros primos"<<endl;
    cout<<"ingrese una opcion: ";cin>>x;
    switch (x){
       case 1:
       cout<<"ordenar 4 numeros por metodo de burbuja"<<endl;
       cout<<"ingresar #1: ";cin>>n[0];
       cout<<"ingresar #2: ";cin>>n[1];
       cout<<"ingresar #3: ";cin>>n[2];
       cout<<"ingresar #4: ";cin>>n[3];    
       LI = 0;
       LS = (sizeof(n)/sizeof(int))-1;
       for(i= LI;i<=LS-1;i++){
              for(j=LI;j<=LS-1;j++){
                 if(n[j]>n[j+1]){
                  tmp=n[j];
                  n[j]=n[j+1];
                  n[j+1]=tmp;
                  }
              }
       }
       cout<<"ordenado"<<endl;
       cout<<"_________________"<<endl;
       cout<<"ingresar #1: "<<n[0]<<endl;
       cout<<"ingresar #2: "<<n[1]<<endl;
       cout<<"ingresar #3: "<<n[2]<<endl;
       cout<<"ingresar #4: "<<n[3]<<endl;
       system("pause");
       break;  
       case 2:
       cout<<"¿cuantos elementos de A se encuentran en B?"<<endl;
       cout<<"arregloA"<<endl;
       cout<<"________________"<<endl;
       cout<<"ingresar #1: ";cin>>a[0];
       cout<<"ingresar #2: ";cin>>a[1];
       cout<<"ingresar #3: ";cin>>a[2];
       cout<<"ingresar #4: ";cin>>a[3];    
       cout<<endl;
       cout<<"arregloB"<<endl;
       cout<<"________________"<<endl;
       cout<<"ingresar #1: ";cin>>b[0];
       cout<<"ingresar #2: ";cin>>b[1];
       cout<<"ingresar #3: ";cin>>b[2];
       cout<<"ingresar #4: ";cin>>b[3];  
       for(i=0;i<=3;i++){
            for(j=0;j<=3;j++){
               if(a[i] == b[j])
               c +=1;
               }
       }  
       cout<<"cantidad: "<<c<<endl;
       system("pause");
       break;
       case 3:
           
       cout<<"cantidad de numeros primos"<<endl;
       cout<<"ingresar #1: ";cin>>z[0];
       cout<<"ingresar #2: ";cin>>z[1];
       cout<<"ingresar #3: ";cin>>z[2];
       cout<<"ingresar #4: ";cin>>z[3];
       cout<<"ingresar #5: ";cin>>z[4];
       for(i=0;i<=4;i++){
       flag=true;
       for(d=2;d<=z[i]/2;d++){              
       if(z[i]%d==0){
       flag=false;
       break;}    
       }
       if(flag)
        c+=1;
       }                  
       cout<<"cantidad: "<<c<<endl;
       system("pause");
       break;
       default:
       cout<<"ERROR"<<endl;
       system("pause");
       break;
       }}
       while(x!=0);
       system("read");
       return 0;
       }
       float ordenacion_burbuja(int,int,int,int,float,float)
      { return
       LI = 0;
       LS = (sizeof(n)/sizeof(int))-1;
       for(i= LI;i<=LS-1;i++){
              for(j=LI;j<=LS-1;j++){
                 if(n[j]>n[j+1]){
                  tmp=n[j];
                  n[j]=n[j+1];
                  n[j+1]=tmp;
                  }}}
        }  
        float cantidaddeelementos_deAenB(int,int,int,int,int,int,int,int)
        { return
         c=0;
         for(i=0;i<=3;i++){
            for(j=0;j<=3;j++){
               if(a[i] == b[j]){
               c +=1;}
               }}  
         }
         float cantidadde_numerosprimos(int,int,int,int,int)
         {return
         c=0;
        for(i=0;i<=4;i++){
        flag=true;
        for(d=2;d<=z[i]/2;d++){              
        if(z[i]%d==0){
        flag=false;
        break;}    
        }
        if(flag)
        c+=1;
       }
       }
       
       
       
       
             
                                                       

No hay comentarios:

Publicar un comentario