Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define NUM_ARREGLOS 10
- void verarreglo(int *ver, int na){ // NA ES = A NUM_ARREGLOS
- int i;
- for(i = 0; i != na; i++){
- printf("N%d) %d\n",i,ver[i]);
- }
- }
- int calcular_p(int arreglos[NUM_ARREGLOS]){ // CALCULAR PARES
- int t_pares = 0;
- int i = 0;
- for(i = 0; i != NUM_ARREGLOS; i++) if(arreglos[i] % 2 == 0) t_pares++; // TOTAL DE PARES
- return t_pares; // DEVOLVEMOS EL VALOR DE T_PARES.
- }
- int sumar_arreglo(int *arreglos, int na){
- int temp=0; //TEMPORAL
- int i = 0;
- for(i = 0;i!= na; i++) temp += arreglos[i];
- return temp; // RETORNAMOS LA VARIABLE TEMPORAL QUE ES LA SUMA DE TODOS LOS ARREGLOS-
- }
- void ordenarburbuja(int *arreglos, int na){ // NA ES = A NUM_ARREGLOS
- //ALGORITMO BURBUJA
- int temp;
- int z, v;
- for(z = 1; z < na; ++z) {
- for(v = 0; v < (na - z); v++) {
- if(arreglos[v] > arreglos[v+1]){
- temp = arreglos[v];
- arreglos[v] = arreglos[v + 1];
- arreglos[v + 1] = temp;
- }
- }
- }
- }
- int main(int argc, char **argv){
- int arreglo[NUM_ARREGLOS];
- int i, z;
- for(i = 0; i != NUM_ARREGLOS; i++){ // Creamos a I y pedimos que se repita el ciclo hasta que I (Ingresados) Sea igual a la cantidad de arreglos definida.
- printf("Ingrese el arreglo %d: ", i+1);
- scanf(" %d",&arreglo[i]); // Pedimos el arreglo y lo ingresamos en la posicion I..
- for(z = 0; z != i; z++){ // Creamos a Z Y pedimos que se repita el for hasta que Z sea igual a I (Ingresados)
- if(arreglo[i] == arreglo[z]){ // COMPROBAMOS QUE EL ARREGLO INGRESADO (i) NO SEA IGUAL A NINGUNO DE LOS YA DEFINIDOS. (Z)
- printf("No se pueden repetir\n");
- i--; // Restamos uno a i para volver un ciclo antras en el for.
- break; //Salir del ciclo for
- }
- }
- }
- printf("Orden ingresado:\n");
- verarreglo(arreglo, NUM_ARREGLOS);
- printf("Orden burbuja:\n");
- ordenarburbuja(arreglo, NUM_ARREGLOS);
- verarreglo(arreglo, NUM_ARREGLOS);
- //Crear arreglo par/inpar:
- int num_pares[calcular_p(arreglo)];
- int num_impares[(NUM_ARREGLOS-calcular_p(arreglo))];
- printf("Hay %d y %d impares\n", calcular_p(arreglo), (NUM_ARREGLOS-calcular_p(arreglo)) );
- //AGREGAR PARES A ARREGLO
- int pares = 0, impares = 0;
- for(i = 0; i != NUM_ARREGLOS; i++) //SIZEOF ES PARA CALCULAR EL TAMAÑO DEL ARREGLO.
- {
- if(arreglo[i] % 2 == 0){
- num_pares[pares] = arreglo[i];
- pares++; // CANTIDAD DE PARES ENCONTRADOS HASTA EL MOMENTO.
- }
- else{
- num_impares[impares] = arreglo[i];
- impares++;
- }
- }
- printf("Pares(%d):\n", pares);
- verarreglo(num_pares, pares);
- printf("Impares(%d):\n", impares);
- verarreglo(num_impares, impares);
- int suma_de_todos = sumar_arreglo(arreglo, NUM_ARREGLOS); // DEVOLVEMOS EL VALOR DE LA SUMA TOTAL
- int suma_p = sumar_arreglo(num_pares, pares); // Asignamos el valor de la suma total a la variable suma_p
- int suma_i = sumar_arreglo(num_impares, impares); // IGUAL PERO A SUMA_I
- printf("Suma total: %d - Suma pares %d - Suma impares %d\n", suma_de_todos, suma_p, suma_i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement