lunes, 6 de agosto de 2012

PROGRAMA DE ASCENDENTE Y DESCENDENTE CON LETRAS

código


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#define ASCENDENTE 1
#define DESCENDENTE 0

typedef struct _nodo {
char valor;
struct _nodo *siguiente;
struct _nodo *anterior;
} tipoNodo;

typedef tipoNodo *pNodo;
typedef tipoNodo *Lista;

/* Funciones con listas: */
void Insertar(Lista *l, char v);
void Borrar(Lista *l, char v);

void BorrarLista(Lista *);
void MostrarLista(Lista l, char orden);

int main() {
int a,x=0,c;
char b,d;
Lista lista = NULL;
pNodo p;
printf("\nIngresa la cantidad de elementos a Insertar:");
scanf("%d",&a);
fflush(stdin);
for(x=1;x<=a;x++)
{fflush(stdin);
printf("\nDigita una Letra:");
scanf("%c",&b);
Insertar(&lista, b);
}

MostrarLista(lista, ASCENDENTE);

MostrarLista(lista, DESCENDENTE);
getch();
printf("\nIngresa la cantidad de elementos a Borrar:");
scanf("%d",&c);
fflush(stdin);
for(x=1;x<=c;x++)
{
printf("\nDigita Letra a Eliminar:");
scanf("%c",&d);

Borrar(&lista, d);
}

MostrarLista(lista, ASCENDENTE);
MostrarLista(lista, DESCENDENTE);

BorrarLista(&lista);
getch();
return 0;
}

void Insertar(Lista *lista, char v)
{
pNodo nuevo, actual;

/* Crear un nodo nuevo */
nuevo = (pNodo)malloc(sizeof(tipoNodo));
nuevo->valor = v;

/* Colocamos actual en la primera posición de la lista */
actual = *lista;
if(actual) while(actual->anterior) actual = actual->anterior;
/* Si la lista está vacía o el primer miembro es mayor que el nuevo */
if(!actual || actual->valor > v) {
/* Añadimos la lista a continuación del nuevo nodo */
nuevo->siguiente = actual;
nuevo->anterior = NULL;
if(actual) actual->anterior = nuevo;
if(!*lista) *lista = nuevo;
}
else
{
/* Avanzamos hasta el último elemento o hasta que el siguiente tenga
un valor mayor que v */
while(actual->siguiente &&actual->siguiente->valor <= v)
actual = actual->siguiente;
/* Insertamos el nuevo nodo después del nodo anterior */
nuevo->siguiente = actual->siguiente;
actual->siguiente = nuevo;
nuevo->anterior = actual;
if(nuevo->siguiente) nuevo->siguiente->anterior = nuevo;
}
}

void Borrar(Lista *lista, char v) {
pNodo nodo;

/* Buscar el nodo de valor v */
nodo = *lista;
while(nodo && nodo->valor < v) nodo = nodo->siguiente;
while(nodo && nodo->valor > v) nodo = nodo->anterior;

/* El valor v no está en la lista */
if(!nodo || nodo->valor != v) return;

/* Borrar el nodo */
/* Si lista apunta al nodo que queremos borrar, apuntar a otro */
if(nodo == *lista)
if(nodo->anterior) *lista = nodo->anterior;
else *lista = nodo->siguiente;

if(nodo->anterior) /* no es el primer elemento */
nodo->anterior->siguiente = nodo->siguiente;
if(nodo->siguiente) /* no es el último nodo */
nodo->siguiente->anterior = nodo->anterior;
free(nodo);
}

void BorrarLista(Lista *lista) {
pNodo nodo, actual;

actual = *lista;
while(actual->anterior) actual = actual->anterior;

while(actual) {
nodo = actual;
actual = actual->siguiente;
free(nodo);
}
*lista = NULL;
}

void MostrarLista(Lista lista, char orden) {
pNodo nodo = lista;

if(!lista) printf("Lista vacía");

nodo = lista;
if(orden == ASCENDENTE) {
while(nodo->anterior) nodo = nodo->anterior;
printf("Orden ascendente: ");
while(nodo) {
printf("%c -> ", nodo->valor);
nodo = nodo->siguiente;
}
}
else {
while(nodo->siguiente) nodo = nodo->siguiente;
printf("Orden descendente: ");
while(nodo) {
printf("%c -> ", nodo->valor);
nodo = nodo->anterior;
}
}

printf("\n");
}


Programa en ejecución


lunes, 16 de julio de 2012

ALGORITMO PARA UN PROGRAMA DE LISTA SIMPLE


Algoritmo de un programa  de “Lista simple ligada”

1.- Inicio
2.- INICIO FUNCION INICIAL  (A)
3.-A y B son variables de tipo puntero.
(A)
 A->INFORMACIÓN
 A->LIGA=NULL
       Repetir
(B)
 B->INFORMACIÓN
 B->LIGA=  A y A = B
4.- Fin FUNCION INICIAL
5.- Inicio FUNCION FINAL (A)
A->INFORMACIÓN
A->LIGA=NULL y  T=A
       Repetir
(B)
B->INFORMACIÓN
B->LIGA=NULL, T->LIGA=B y T=B
6.-Fin FUNCION FINAL 
7.- Inicio FUNCION RECURSIVIDAD
8.- Si A =! NULL 
        ENTONCES
A->INFORMACIÓN
           Llamar a RECURSIVIDAD con A->LIGA
9.- Fin FUNCION RESURSIVIDAD
10.-  Inicio FUNCION INSERTAR 
 B= A y BAND= VERDADERO
     mientras (B->INFORMACIÓN =! REF) y (BAND = VERDADERO)
              Si B -> LIGA =! NIL
                                              Entonces
                                                 T= B y B= B-> LIGA
                                              Else
                                                              BAND = FALSO
          Si BAND = VERDADERO entonces
                               (X)
                        X->INFORMACIÓN = DATO
                                              Si A = B
                                                             Entonces
                                                                             X ->LIGA = A y A = X
                                                             Else
                                                                             T ->LIGA =X y X ->LIGA = B
11.- Fin FUNCION INSERTAR
12.-Inicio FUNCION ELIMINAR
13.- B = A y BAND= VERDADERO
 mientras (B->INFORMACIÓN =! X) y  (BAND = VERDADERO)
Si B ->LIGA =! NULL
                                              Entonces
T = B y B = B -> LIGA
                                              Else
BAND = FALSO
               Si BAND = FALSO
                               Entonces
                                              Imprimir  ”El elemento no fue encontrado”
                               Else
SI A = B  
                                              Entonces
                                A = B->LIGA
                                              Else
                                                             T -> LIGA=B-> LIGA
14.- Fin FUNCION ELIMINAR
15.- Inicio CUERPO PRINCIPAL
16.- Si ( P =! NULL)
                               Entonces
                                              Si ( A ->INFORMACIÓN = X )
                                              Entonces
               Imprimir   “El elemento se encuentra en la lista”
                                              Else
                BUSCARRECURSIVO con a -> LIGA y X
                               
                           Else
               Imprimir     “El elemento no se encuentra en la lista”
17.- Fin CUERPO PRINCIPAL
 
 
 
 
 



ALGORITMO DEL PROGRAMA COTIDIANO


Algoritmo del programa con fila “PROBLEMA COTIDIANO”

1.- INICIO
2.- Declarar variable nombrec, nombret, ntaxi y destino
3.- Inicio FUNCION ACOLAR
4.- struct cola*nuevo;
5.- Introducir datos “numero de taxi, nombre del taxista, nombre del cliente y destino”
6.- nuevo->sig=NULL;
           if(princ==NULL)
             princ=nuevo;
              fin=nuevo;
                   else
                     fin->sig=nuevo;
                         fin=nuevo;
                             j++;
 7.- FIN FUNCION ACOLAR
8.- Inicio  FUNCION MOSTRAR
9.- struct cola *aux;
              aux=princ;
                  if(aux==NULL){
            Imprimir "COLA VACIA"
                               else       
                                      while(aux!=NULL)
10.- IMPRIMIR  “Numero de taxi, nombre del taxista, nombre del cliente, destino”
                aux=aux->sig;
11.- FIN FUNCION MOSTRAR
12.- Inicio FUNCION DESACOLAR
13.- struct cola *aux;
                  struct cola *aux1;
                         int cont;
                 aux=princ;
                aux1=princ;
                                  cont=0;
           while(aux!=NULL)
                if(aux->ntaxi==aux1->ntaxi)
                    if(cont==0)
                          princ=princ->sig;
              aux=aux->sig;
              aux1=aux;
              cont=1;
 14.- FIN FUNCION DESACOLAR
15.- Inicio CUERPO PRINCIPAL
16.- int opc;
           Do
          Imprimir “REGISTRO DE PERSONAS ***SITIO DE TAXIS TULTITLAN”
          Imprimir “1. INGRESAR DATOS A LA COLA    2. MOSTRAR DATOS DE LA COLA  3. RETIRAR
                                                                                                                 DATOS EN LA COLA    4. SALIR”
17.- switch (opc)
           case 1:
            acolar();
              break;
                    case 2:
                       mostrar();
                               break;
                    case 3:
                        desacolar();
                                break;
                     default:
18.- Imprimir  "SALIR DEL SISTEMA"
                                 break;
                     while(opc!=4);

Programa en Dev de colas


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct cola{
int ntaxi;
char nombret[20];
char nombrec[20];
char destino[20];
struct cola *sig;
}*princ, *fin;
int j=0;
void acolar(){
struct cola *nuevo;
nuevo=(struct cola *)malloc(sizeof(struct cola));
printf("INTRODUCIR NO. DE TAXI:\n ");
scanf("%d",&nuevo->ntaxi);
printf("INTRODUCIR NOMBRE DEL TAXISTA:\n ");
scanf("%s",&nuevo->nombret);
printf("INTRODUCIR NOMBRE DEL CLIENTE:\n ");
scanf("%s",&nuevo->nombrec);
printf("INTRODUCIR DESTINO:\n");
scanf("%s",nuevo->destino);
nuevo->sig=NULL;
if(princ==NULL){
princ=nuevo;
fin=nuevo;
}else{
fin->sig=nuevo;
fin=nuevo;
}
j++;
}
void mostrar(){
struct cola *aux;
aux=princ;
if(aux==NULL){
printf("COLA VACIA\n");
}else{      
while(aux!=NULL){
printf("NUMERO DE TAXI: %d\nNOMBRE DEL TAXISTA: %s\n NOMBRE DEL CLIENTE: %s\n DESTINO: %s\n\n\n", aux->ntaxi,aux->nombret, aux->nombrec, aux->destino);
aux=aux->sig;
}
}
}
void desacolar(){
struct cola *aux;
struct cola *aux1;
int cont;
aux=princ;
aux1=princ;
cont=0;
while(aux!=NULL){
if(aux->ntaxi==aux1->ntaxi){
if(cont==0){
princ=princ->sig;
}
}
aux=aux->sig;
aux1=aux;
cont=1;
}
}
main(){
int opc;
do{
printf("\n\n\n\t\tREGISTRO DE PERSONAS ***SITIO DE TAXIS TULTITLAN\t\t\t\t\n");
printf("\n\t\t\t1. INGRESAR DATOS A LA COLA\n\t\t\t2. MOSTRAR DATOS DE LA COLA\n\t\t\t3. RETIRAR DATOS EN LA COLA\n\t\t\t4. SALIR\n\t\t\t");
scanf("%d", &opc);
system("cls");
switch (opc){
case 1:
acolar();
break;
case 2:
mostrar();
break;
case 3:
desacolar();
break;
default:
printf("SALIR DEL SISTEMA\n");
break;
}
}while(opc!=4);
}


PROGRAMA CORRIDO




lunes, 2 de julio de 2012

PROGRAMA EN DEV PARA ENLISTAR Y GUARDAR DATOS


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#define MAX 100

char*p[MAX];
char*crecup(void);
void calmac (char*c);
void nombre(void);
int spos,rpos;
void intro (void),revisar(void),borrar(void);
int main(void)
{
char s[80];
register int t;
spos=0;
rpos=0;

for(t=0;t<MAX;++t)p[t]=NULL;
for(;;)
{
printf("\n(I)introducir\n(L)listar\n(B)borrar\n(N)nombre del programador\n(S)salir\n");
printf("\n\nEscribir tu accion a realizar:\n");
gets(s);
*s=toupper(*s);
switch(*s)
{
case 'I':intro();break;
case 'L':revisar();break;
case 'B':borrar();break;
case 'N':nombre();break;
case 'S':exit(0);
}
}
system("pause");
return 0;
}
void intro (void)
{
char s[100],*p;
do
{
printf("\nIntroduce todos tus datos deseados%d:\n",spos+1);
printf("(SOLO DA (ENTER) PARA REGRESAR AL MENU PRINCIPAL)");
gets(s);
if(*s=='\0')break;
p=(char*)malloc(strlen(s)+1);
if(!p)
{
printf("NO HAY MEMORIA RESERVADA\n");
return;
}
strcpy(p,s);
calmac(p);
}
while(*s);
}
void revisar(void)
{
int t;
if(rpos==spos)
{
printf("NO HAY DATOS\n");
return;
}
for(t=rpos;t<spos;t++)
printf("\n CADENA ES %d: %s\n",t+1,p[t]);
}
void borrar(void)
{
char*q;
q=crecup();
if(q==NULL)
{
printf("NO HAY DATOS!!!\n");
return;
}
printf("ESTE ES EL DATO RECUPERADO Y BORRADO: DATO NUMERO %d: %s\n",rpos+1,q);
free(q);
}
void nombre(void)
     {
          printf("\nSilvia Veronica Palacios Garcia");
           printf("\nMATRICULA: 1311120138 GRUPO: 110353\n\n");
     }  
void calmac(char*q)
{
if(spos==MAX)
{
printf("\nLA COLA ESTA LLENA\n");
return;
}
p[spos]=q;
spos++;
}
char*crecup(void)
{
if(rpos==spos)
{
printf("\nNO HAY DATOS\n");
return NULL;
}
rpos++;
return p[rpos-1];
}

PROGRAMA EN EJECUCION



martes, 26 de junio de 2012


PROGRAMA PALINDROMOS END DEV C++

#define MAX 3
#include<stdio.h>
#include<conio.h>
#include<string.h>
void push(char i);
char pop(void);
int top=0;
char pila[MAX];
main()
{
int top=0;
char aux[MAX];
char original[MAX];
int a;
char b;
strcpy(aux,"");
for(a=0;a<MAX;a++){
fflush(stdin);
printf("INGRESA UNA LETRA:");
scanf("%c",&b);
push(b);  
}
printf("PILA:%s",pila);
strcpy(original,pila);
printf("\n\n%s\n%s",original,pila);
printf("\nVALOR POP\n");
for(a=0;a<3;a++)
{
aux[a]=pop();
}
printf("%d",strlen(aux));

if(strcmp(original,aux)==0)
printf("PALINDROMO");
else
printf("NO ES");
      getch();
      }
void push(char i)
{
     if(top>=MAX)
     {
                 printf("\nPILA LLENA\n\n");
                 return;                         
                 }
     pila[top]=i;
     top++;
       
     }
char pop(void)
{
    top--;
    if(top<0)
    {
    printf("\nPILA VACIA\n");
    return(0);
             }
    return pila[top];
}


PROGRAMA EN EJECUCION





domingo, 3 de junio de 2012

PROGRAMA EN DEV C++ DE VECTORES

Este programa que calcula la suma de 2 vectores, también muestra la longitud y el angulo del vector resultante:


Código:




#include<conio.h>
#include<stdio.h>
#include<math.h>
struct vector
{
int k1,m,k2;
double cy,cx,resul,rx,ry,ang,dy,dx;
};
struct vector vec[1];
main()
{
void Seno(void);
printf("Ingresa vector:");
scanf("%d",&vec[1].k1);
printf("Ingresa vector:");
scanf("%d",&vec[1].k2);
printf("Escribe el angulo:");
scanf("%d\n",&vec[1].m);
//seno
printf("________SENO y COSENO EN F2__________\n");
double c;
c=sin(vec[1].m);
printf("c=Sen(q); \n");
printf("%f\n\n",c);
vec[1].cy=(vec[1].k1)*c;
printf("cy=f1*c:\n ");
printf("%f\n\n",vec[1].cy);
//Coseno
double d;
d=cos(vec[1].m);
printf("d=cos(m); \n");
printf("%f\n\n",d);
vec[1].cx=(vec[1].k1)*d;
printf("bx=k1*c: \n");
printf("%f\n\n",vec[1].cx);
printf("______________________________________\n\n");
printf("________SENO y COSENO EN VECTORES________\n");
//seno
vec[1].dy=((vec[1].k2)*c);
printf("dy=f2*c: \n");
printf("%f\n\n",vec[1].cy);
//coseno
vec[1].cx=((vec[1].k2)*d);
printf("dx=k2*b: \n");
printf("%f\n\n",vec[1].dx);
printf("______________________________________\n\n");
printf("___________SUMA DE VECTORES___________\n");
vec[1].rx=vec[1].cx+vec[1].dx;
printf("rx=cx+dx: \n");
printf("%f\n\n",vec[1].rx);
vec[1].ry=vec[1].cy+vec[1].dy;
printf("ry=cy+dy: \n");
printf("%f\n\n",vec[1].ry);
printf("______________________________________\n\n");
printf("___________RESULTADO DE VECTORES___________\n");
double k1,k2;
k1=(vec[1].rx)*(vec[1].rx);
printf("(rx)*(rx): %f\n",k1);
k2=(vec[1].ry)*(vec[1].ry);
printf("(ry)*(ry):%f \n",k2);
vec[1].resul=sqrt(k1+k2);
printf("Resultante de los vectores; %f\n",vec[1].resul);
printf("______________________________________\n\n");
printf("___________ANGULOS DE VECTORES___________\n");
double rk,nn;
nn=vec[1].ry/vec[1].rx;
printf("Division y/x: : %f\n",nn);
vec[1].ang= atan(nn);
printf("Angulo Radianes: %f\n",vec[1].ang);
rk=(180*vec[1].ang)/(3.141592654);
printf("La conversion es: %f\n",rk);
getch();
}



Programa en ejecución:



lunes, 28 de mayo de 2012

Programa para escribir datos de nuestro artista favorito en DevC++

Este programa sirve para pedir los datos mas relevantes de nuestro cantante favorito, como su nombre, edad, pais de origen, etc:

codigo:


#include<stdio.h>
#include<conio.h>
struct artista
{
       int edad;
       char nombre[30];
       char grupo[30];
       char cancion[30];
       char pais[30];

       };
int i;
main()
{
struct artista x[1];

i=0;
      printf("Datos interesantes\n");
for(;;){
      fflush(stdin);

      printf("Introduce su nombre\n");
      gets(x[i].nombre);
      printf("Introduce su edad\n");
      scanf("%d",&x[i].edad);
      fflush(stdin);
      printf("Introduce grupo\n");
      gets(x[i].grupo);
      printf("cancion\n");
      gets(x[i].cancion);          
      printf("pais de origen\n");
      gets(x[i].pais);


      printf("\n____________________________________________________\n");
      printf("Nombre: %s\n",x[i].nombre);
       printf("\n____________________________________________________\n");
      printf("Edad: %d",x[i].edad);
      printf("\n____________________________________________________\n");
      printf("grupo que pertenece: %s\n",x[i].grupo);
      printf("\n____________________________________________________\n");
      printf("cancion: %s\n",x[i].cancion);
      printf("\n____________________________________________________\n");
      printf("pais de origen: %s\n",x[i].pais);
             i++;
      if(i>0)
      {      printf("\nDirectorio lleno!!!\n");
             getch();
              break;
              }
      getch();
      }
      i++;
      }

Programa en ejecucion:




Resultado:



sábado, 26 de mayo de 2012

PROGRAMA QUE PIDE NÚMEROS Y SUMA PARES E IMPARES POR SEPARADO

Este programa fue hecho en DevC++ y nos pide digitar 10 números cualesquiera, y el programa los dividirá en números pares e impares, y hará la suma para los dos grupos de números por separado.

el código:




#include <stdio.h>
#include <conio.h>
void datos (void);
main()
{
int x,sp=0,si=0,st;
float prom,y;
int n[10];
for (x=0;x<10;x++)
{
printf("Escribe el numero: %d\n",x+1);
scanf("%d", & n[x]);
}
for(x=0;x<10;x++)
{
if(n[x]%2==0)
sp=sp+n[x];
else
si=si+n[x];
}
y=sp+si;
printf("El total de los numeros pares es de: %d\n", sp);
printf("El total de los numeros impares es de:%d\n", si);
printf("La suma de todos los numeros es de: %.2f\n", y);
void datos (void);
{
printf("Nombre:Silvia Veronica Palacios Garcia\n");
printf("Grupo:353\n");
}
getch();
}

El programa corriendo


El resultado es:



domingo, 20 de mayo de 2012

PROGRAMA PARA OBTENER EL SUBTOTAL DE UNA COMPRA

Este programa hecho en DevC++, esta basado en la formula:

subtotal = cantidad*precio

código:



#include<stdio.h>
#include<conio.h>
float subtotal (float c,float p);
void datos (void);
main ()
{
float c,p,subto;
printf("Subtotal de la compra\n");
printf("Compra\n");
scanf("%f",&c);
printf("Total de la compra\n");
scanf("%f",&p);
subto=subtotal (c,p);
printf("Resultado Final= %f \n",subto);
datos();
getch();
}
float subtotal (float c,float p)
{
return (c*p);
}
void datos (void)
{
printf("VERONICA PALACIOS\n");
printf("353\n");
}


Programa en ejecución.



El resultado:



PROGRAMA PARRA OBTENER EL VOLUMEN DE UN CONO

en este programa el objetivo es obtener el volumen de un cono a partir de la formula:

V=pi(3.1416)*r2*h/3


código:


#include<conio.h>
#include<stdio.h>
float g,pi=3.1416;
float a,h;
float promedio(float x,float y);
void datos (void);
main ()
{
printf("Radio\n");
scanf("%f",&a);
printf("Altura\n");
scanf("%f",&h);
g=promedio(a,h);
printf("resultado=%f\n",g);
datos();
getch();
}
float promedio(float x,float y)
{
return(((pi*(x*x))*y)/3);
}
void datos (void)
{
printf("VERONICA PALACIOS GARCIA\n");
printf("353\n");
}

ejecución del programa:


el resultado:


PROGRAMA PARA SACAR EL PROMEDIO DE 5 NUMEROS

este programa, fue hecho en Dev c++.

código:


#include<stdio.h>
#include<conio.h>
#include<math.h>
float promedio (float a,float b,float c,float d,float e);
void datos (void);
main ()
{
float a,b,c,d,e,f;
printf("promedio de 5 numeros\n");
printf("numero 1\n");
scanf("%f",&a);
printf("numero 2\n");
scanf("%f",&b);
printf("numero 3\n");
scanf("%f",&c);
printf("numero 4\n");
scanf("%f",&d);
printf("numero 5 \n");
scanf("%f",&e);
f=promedio (a,b,c,d,e);
printf("resultado = %f \n",f);
datos();
getch();
}
float promedio (float a,float b,float c,float d,float e)
{
return ((a+b+c+d+e)/5);
}
void datos (void)
{
printf("VERONICA PALACIOS GARCIA\n");
printf("353\n");
}

A continuación la ejecución del programa


el resultado es:



PROGRAMA PARA CALCULAR EL VOLUMEN DE UNA ESFERA

para este programa, es necesario tener la formula para esta operación:


v=4/3*pi(3.1416)*r3


el código es el siguiente:



#include<stdio.h>
#include<conio.h>
float volumen (float r);
main ()
{
float r,vol;
printf("volumen\n");
printf("radio r\n");
scanf("%f",&r);
vol=volumen(r);
printf("resultado=%f\n",vol);
getch ();
}
float volumen (float r)
{
return (4/3.0*3.1416*(r*r*r));
}


nuestra prueba del programa:




ahora como dato ingresaremos el numero 20.




nuestro resultado es:



sábado, 19 de mayo de 2012

PROGRAMA PARA OBTENER EL AREA DE UN CIRCULO

Este programa fue hecho para que al ingresar datos, podamos obtener el área del circulo a través de la formula:
pi(3.1416)*r2
el programa fue hecho en DEV C++


el código:



#include<conio.h>
#include<stdio.h>
float area(float r);
main()
{
      float r,a;
      printf("area\n");
      printf("radio r\n");
      scanf("%f",& r);
      a=area(r);
      printf("resultado=%f\n",a);
      getch();
      }
      float area(float r)
      {
            return(3.1416*(r*r));
            }


Ejecución del programa


Ahora ingresaremos nuestros datos


El resultado es: