1 / 10

Ejercicios de Arreglos y Funciones “En C”

Ejercicios de Arreglos y Funciones “En C”. Semestre de Otoño 2006. Claudio Gutiérrez-Soto. Destrezas Esperadas. Solucionar un problema utilizando funciones, sin preocuparse de su implementación. Utilizar algunas funciones incorporadas en C, para el manejo de cadenas. Ejercicios 1.

malaya
Télécharger la présentation

Ejercicios de Arreglos y Funciones “En C”

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ejercicios de Arreglos y Funciones“En C” Semestre de Otoño 2006 Claudio Gutiérrez-Soto

  2. Destrezas Esperadas • Solucionar un problema utilizando funciones, sin preocuparse de su implementación. • Utilizar algunas funciones incorporadas en C, para el manejo de cadenas

  3. Ejercicios 1 • Crear una función que cuente cuántas palabras tiene una cadena. La cadena puede estar separada por espacios, puntos y puntos y comas.

  4. Solución 1 int CuentaPalabras(char arreglo[]) { int i,cont; for(i=0,cont=0,pal=0; arreglo[i]!=‘\0’;i++) if(arreglo[i]!=‘ ‘ && arreglo[i]!=‘.’ && arreglo[i]!=‘;’) pal++; else if(pal!=0) { cont++; pal=0; } else continue; if(pal!=0) return(cont+1); else return(cont); }

  5. Ejercicio 2 • Crear una función que calcule la transpuesta de una matriz de 5x5: Ejemplo, de una matriz de 3x3 a b c a d g d e f = b e h g h i c f i

  6. Solución 2 void Traspuesta(int matriz[][5]) { int MatAux[5][5],i,j; for(i=0;i<5;i++) for(j=0;j<5;j++) MatAux[j][i]=matriz[i][j]; for(i=0;i<5;i++) for(j=0;j<5;j++) matriz[i][j]=MatAux[i][j]; }

  7. Ejercicio 3 • Crear una función que determine si dos arreglos contienen los mismos elementos. Considere que los arreglos pueden estar desordenados. Los arreglos pueden ser de cualquier tamaño.

  8. Solución 3 int VerificaIguales(int arr1[], int arr2[],int indice) { int i,j,encontrado,stop; for(i=0,stop=0;i<indice && !stop;i++) { for(j=0,encontrado=0;j<indice && !encontrado;j++) if(arr1[i]==arr2[j]) encontrado=1; else continue; if(encontrado==0) stop=1; else continue; } return(!stop); }

  9. Ejercicio 3 • Crear una función que determine si una cadena es una subcadena de otra cadena.

  10. Solución 3 int SubCadena(char cad[], char Sub[]) { int i,LCad,LSub; char CadAux[20]; LCad=largo(cad); LSub =largo(Sub); if(LSub<=LCad) { for(i=0;cad[i]!=‘\0’;i++) if(cad[i]==Sub[0]) { Copiar_Iesimo(cad,i,CadAux); if(Comparar(CadAux,Sub)) return(1); else continue;; } else continue; return(0); }else return(0); }

More Related