Skip to content

Instantly share code, notes, and snippets.

@Gords
Created November 23, 2014 23:17
Show Gist options
  • Save Gords/a689b51c15d6959e215d to your computer and use it in GitHub Desktop.
Save Gords/a689b51c15d6959e215d to your computer and use it in GitHub Desktop.
#include <stdio.h>
void intercambio(int *uno, int *dos);
int a,b;
int main(int argc, const char * argv[])
{
printf("Ingrese dos numeros para intercambiar sus valores: ");
printf("ingrese el primer numero: ");
scanf("%d",&a);
printf("Ingrese el segundo numero: ");
scanf("%d",&b);
int *pa = &a;
int *pb = &b;
intercambio(pa, pb);
printf("los nuevos valores de estos numeros son a = %d, y b = %d",a,b);
return 0;
}
void intercambio(int *uno, int *dos)
{
int c = a;
*uno = b;
*dos = c;
}
//
// main.c
// exam3erParcialTema4
//
// Created by Fernando Ramirez on 18/11/14.
// Copyright (c) 2014 Fernando Ramirez. All rights reserved.
//
#include <stdio.h>
struct hora
{
int hora;
int minutos;
};
struct hora hora1;
struct hora hora2;
void cargar_hora(int c,int h, int m);
void imprimir_hora(int c, int b, int a);
int diferencia_hora(int a, int b, int c, int d);
int main(int argc, const char * argv[])
{
int a,b,c,d,e,f,g;
printf("ingrese uno para cargar la primera hora o dos para cargar la segunda hora: ");
scanf("%d",&a);
printf("ingrese la hora: ");
scanf("%d",&b);
printf("ingrese los minutos: ");
scanf("%d",&c);
cargar_hora(a,b,c);
imprimir_hora(a, b, c);
printf("\n Ingrese dos horas para compararlas \n");
printf("Ingrese la primera hora: ");
scanf("%d",&d);
printf("Ingrese los minutos: ");
scanf("%d",&e);
printf("Ingrese la segunda hora: ");
scanf("%d",&f);
printf("Ingrese los minutos: ");
scanf("%d",&g);
printf("El resultado es: %d minutos", diferencia_hora(d,e,f,g));
return 0;
}
void cargar_hora(int c,int h, int m)
{
if (c == 1) {
hora1.hora= h;
hora1.minutos = m;
}else if(c==2)
{
hora2.hora = h;
hora2.minutos=m;
}
else
{
printf("error, por favor ingrese uno o dos");
}
}
void imprimir_hora(int c, int b, int a)
{
if (c == 1) {
printf("%d:",hora1.hora);
printf("%d",hora1.minutos);
}else if(c==2)
{
printf("%d:",hora2.hora);
printf("%d",hora2.minutos);
}
}
int diferencia_hora(int a, int b,int c,int d)
{
int h1,h2, h3;
hora1.hora = a;
hora1.minutos = b;
hora2.hora = c;
hora2.minutos = d;
h1 = hora1.hora*60+hora1.minutos;
h2 = hora2.hora*60+hora2.minutos;
if(h1>h2)
{
h3=h1-h2;
}
else
{
h3 = h2-h1;
}
return h3;
}
//
// main.c
// TareaArray
//
// Created by Fernando Ramirez on 17/11/14.
// Copyright (c) 2014 Fernando Ramirez. All rights reserved.
//
#include <stdio.h>
int main(int argc, const char * argv[])
{
//int i = 0;
int j = 0;
int o [] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
/*printf("Ingrese 20 numeros: ");
while (i<20) {
scanf("%d",&o[i]);
i++;
}*/
while (j<20) {
if(o[j]%2 ==0)
{
printf("es par \n");
}else
{
printf("es impar \n");
}
j++;
}
return 0;
}
//
// main.c
// TareaFunciones
//
// Created by Fernando Ramirez on 17/11/14.
// Copyright (c) 2014 Fernando Ramirez. All rights reserved.
//
#include <stdio.h>
int perro(int uno, int dos);
char gato(char uno);
int poN(int num);
int main()
{
int a,b,c;
char letra;
printf("Ingrese dos numeros para comparar \n");
printf("Ingrese el primero: ");
scanf("%d",&a);
printf("Ingrese el segundo: ");
scanf("%d",&b);
printf("%d\n",perro(a, b));
printf("Ingrese una letra: ");
scanf("%s",&letra);
printf("%hhd\n",gato(letra));
printf("Ingrese un numero para saber si es positivo o negativo: ");
scanf("%d",&c);
printf("%d",poN(c));
return 0;
}
int perro (int uno, int dos)
{
if (uno>dos) {
return uno;
}else if(uno<dos)
{
return dos;
}else
{
return printf("Ambos son iguales");
}
}
char gato (char uno)
{
switch (uno) {
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("es vocal");
break;
default:
printf("no es vocal");
break;
}
return 0;
}
int poN (int num)
{
if (num>=1) {
return printf("P");
} else {
return printf("N");
}
}
//
// main.c
// tareaStruct
//
// Created by Fernando Ramirez on 17/11/14.
// Copyright (c) 2014 Fernando Ramirez. All rights reserved.
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct publisher
{
char nombre[30];
int costo;
};
struct juego
{
char nombre[30];
int anho;
struct publisher pub;
}juegoUno;
int main(int argc, const char * argv[])
{
char aux =
printf("Ingrese un nombre");
scanf("%30s",(strncpy(juegoUno.pub.nombre)));
juegoUno.pub.costo = 20;
printf("%s\n",juegoUno.pub.nombre);
printf("%i",juegoUno.pub.costo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment