Created
April 27, 2017 14:14
-
-
Save benoffi7/4e7cf5acd54ddcd82c414053a9d5beb9 to your computer and use it in GitHub Desktop.
Ejercitación Parcial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include "pila.h" | |
float porcentaje(Pila p, int entero); | |
int main() | |
{ | |
/* | |
printf("Hello world!\n"); | |
int a[50] = {0}; | |
int notas [4] = {1,10,10,7}; | |
int cargados = cargarArreglo(a,50); | |
printf("los validos son ... %d\n",cargados); | |
int resultado = promedio(notas); | |
if (resultado == 0) | |
{ | |
printf("desaprobado!\n"); | |
} | |
else | |
{ | |
printf("aprobado!\n"); | |
} | |
*/ | |
Pila p; | |
inicpila(&p); | |
apilar(&p,1); | |
apilar(&p,2); | |
apilar(&p,3); | |
apilar(&p,4); | |
apilar(&p,6); | |
int elementoNuevo = 5; | |
ingresarElemento(&p,elementoNuevo); | |
mostrar(&p); | |
/* | |
int entero = 5; | |
float rta = porcentaje(p,entero); | |
printf("el porcentaje es %f ",rta); | |
sumatoria(a,cargados); | |
int seleccion = 0; | |
int rta = 0 ; | |
printf("que desea buscar? 0 para el menor - 1 para la pos del menor\n"); | |
scanf("%d",&seleccion); | |
rta = ejercicio5(a,cargados,seleccion); | |
if (seleccion == 0) | |
{ | |
printf("el menor de los elementos es ... %d",rta); | |
} | |
else | |
{ | |
printf("la pos del menor de los elementos es ... %d",rta); | |
} | |
*/ | |
return 0; | |
} | |
int cargarArreglo(int a[50], int total) | |
{ | |
char mander = 's'; | |
int validos = 0; | |
while (mander == 's') | |
{ | |
printf("Ingrese un numero para la pos %d\n",validos+1); | |
scanf("%d",&a[validos]); | |
validos++; | |
printf("desea seguir ?"); | |
fflush(stdin); | |
scanf("%c",&mander); | |
} | |
return validos; | |
} | |
int promedio(int notas[4]) | |
{ | |
int suma = 0; | |
int cantidad = 4; | |
float promedioC = 0; | |
int i = 0; | |
int rta = 0; | |
for (i = 0;i<4;i++) | |
{ | |
suma = suma + notas[i]; | |
} | |
promedioC = (float) suma / (float) cantidad; | |
if (promedioC>=7) | |
{ | |
rta = 1; | |
} | |
return rta; | |
} | |
float porcentaje(Pila p, int entero) | |
{ | |
int cantidadTotal = 0; | |
int cantidadEncontrada = 0; | |
while (!pilavacia(&p)) | |
{ | |
if (tope(&p)==entero) | |
{ | |
cantidadEncontrada ++; | |
} | |
cantidadTotal++; | |
desapilar(&p); | |
} | |
float porcentajeC = ( float) (cantidadEncontrada * 100) / (float)cantidadTotal; | |
return porcentajeC; | |
} | |
void sumatoria (int a[50], int validos) | |
{ | |
int suma = 0 ; | |
int i = 0 ; | |
for (i = 0 ; i<validos;i++) | |
{ | |
suma = suma + a[i]; | |
printf("la sumatoria hasta el elemento %d es de : %d\n",i+1,suma); | |
} | |
} | |
int ejercicio5(int a[50],int validos, int seleccion) | |
{ | |
int menor = a [0]; | |
int pos_menor = 0; | |
int i = 0; | |
int rta = 0; | |
for (i = 0 ; i<validos;i++) | |
{ | |
if (menor > a[i]) | |
{ | |
menor = a[i]; | |
pos_menor = i; | |
} | |
} | |
if (seleccion == 0) | |
{ | |
rta = menor; | |
} | |
else | |
{ | |
rta = pos_menor; | |
} | |
return rta; | |
} | |
int ingresarElemento(Pila * pila, int elemento) | |
{ | |
Pila aux; | |
inicpila(&aux); | |
while (!pilavacia(pila) && tope(pila) > elemento) | |
{ | |
apilar(&aux,desapilar(pila)); | |
} | |
apilar(pila,elemento); | |
while (!pilavacia(&aux)) | |
{ | |
apilar(pila,desapilar(&aux)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment