Programas en c
Programa que te realiza una suma y te dice cuanto te tardas en ingresar los valores.
#include < stdio.h >
#inlcude < time.h >
int main(){
time_t start, end; //* declara variables de tipo tiempo
int x,y,sum;
double dif;
time(&start); //* toma el tiempo actual
printf("\n\n-Teclee el primer valor\n");
scanf("%d", &x);
printf("\n\n-Teclee el segundo valor\n");
scanf("%d", &y);
sum=x+y;
time(&end);
dif= difftime(end, start); //* saca la diferencia de ese rango de tiempo
printf("\n\n-Le ha tomado %.f segundos tecleear los valores\n\n", dif);
printf("\n\n-El resultado de la suma es: %d\n",sum);
getche();
return 0;
}
Programa que tira el dado 50 veces y te dice cuanto cayo el primer dado y el segundo y te da la suma de los dados en cada tiro y dice si quieres volver a tirar los dados otra vez.
#inlcude < time.h >
#include < math.h >
int main()
{
int DADO1[36000],DADO2[36000],SUMA[36000],INICIO,OPCION;
do
{
system("cls");
printf("%s%17s%17s%17s\n","TIRO","DADO 1","DADO 2","TOTAL");
do
{
for(INICIO=1;INICIO<=50;INICIO++)
{
DADO1[INICIO]=1+rand ()%6;
DADO2[INICIO]=1+rand ()%6;
SUMA[INICIO]=DADO1[INICIO]+DADO2[INICIO];
printf("%d%17d%17d%17d\n",INICIO,DADO1[INICIO],DADO2[INICIO],SUMA[INICIO]);
}
}
while(INICIO<=50);
printf("\n\nDESEA TIRAR DE NUEVO LOS DADOS= ");
printf("\nSI=1 ");
printf("\nNO=0 ");
scanf("%d",&OPCION);
}
while(OPCION==1);
getch();
return 0;
}
Programa que te muetra los cinco mayores valores de un arreglo de forma descendente.
#inlcude < math.h >
int main()
int n,i,j,A[50],TEMP;
//LLENA EL VECTOR
n=10;
for(i=1;i<=n;i++)
{
printf("Vector Numero %d ",i);
scanf("%d",&A[i]);
}
//REALIZA LA ORDENACION
for(i=1;i<=n-1;i++)
{
for(j=1;j<=n-1;j++)
{
if(A[j]>A[j+1])
{
TEMP= A[j];
A[j] = A[j+1];
A[j+1] = TEMP;
}
}
}
//IMPRIME LOS DATOS ORDENADOS
j=0;
printf("\ndecendente: ");
for(i=n;i>=1;i--){
j++;
if(j<=5)
{
printf(",%d",A[i]);
}
}
getch();
}
SALUDOS A TODOS
ATTE: JESUS ALEJANDRO BELTRAN REYNA
Hay errores de ortografía en tu código. No compilaría bien. Tres puntos para el lab.
ResponderEliminar