Professional Documents
Culture Documents
main(){
float metros,resul,pulg;
int resul2,pulg2;
clrscr();
getch();
}
Volver
void main(){
int prim,seg,resul;
char oper;
clrscr();
if(oper=='+')
resul=prim+seg;
if(oper=='-')
resul=prim-seg;
if(oper=='*')
resul=prim*seg;
if(oper=='/')
resul=prim/seg;
Volver
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 2 of 16
main(){
float uno,dos,tres;
clrscr();
else
printf("\nEl triangulo es isoceles");
getch();
}
Volver
main(){
int alumnos,edad,counter=1;
float promedio,sumaedad=0;
clrscr();
while(1){
sumaedad=sumaedad+edad;
if(counter==alumnos){
break;
}
counter++;
}
promedio=sumaedad/counter;
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 3 of 16
getch();
}
Volver
void main(void){
int notas,reprobados;
clrscr();
int c=1,calif,rep=0;
while(c<=not){
if(calif<7){
rep++;}
c++;
}
return(rep);
}
Volver
Función que lee las matrículas (números enteros) y las calificaciones (tipo char) de
los alumnos de un grupo y las almacene en dos arreglos unidimensionales. La
función deberá leer los datos hasta que se de una matrícula cero la cual indica el fin
de captura. La función regresa el número de alumnos por el mecanismo de return.
Después debe de imprimir el contenido de los arreglos.
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 4 of 16
#include stdio.h
void main(void){
int max=30,matr[29],numalumn;
char calif[29];
clrscr();
numalumn=leedato(matr,calif,max);
printf("\nEl numero de alumnos capturados es %d",numalumn);
despliega(matr,calif,numalumn);
}
int leedato(int *mats,char *califs,int maximo){
int n=0;
while(1){
if(n>=maximo){
printf("\nEl arreglo se encuentra lleno");
getch();
break;
}
printf("\n\nMatricula del alumno %d: ",n+1);
scanf("%d",mats);
if(*mats==0){
break;
}
printf("\nCalificacion del alumno %d: ",n+1);
scanf("%d",califs);
mats++;
califs++;
n++;
}
return n;
}
int i=1;
while(1){
if(i>numcap){
break;
}
printf("\nLa calificacion del alumno %d es %d",*mats,*califs);
i++;
mats++;
califs++;
}
getch();
}
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 5 of 16
Volver
void main(void){
int rango1,rango2,incremento;
char tipo;
clrscr();
tipo=tipoConv();
leeDatos(&rango1,&rango2,&incremento);
if(tipo=='C'){
despliegaCF(&rango1,&rango2,&incremento);
}
else{
despliegaFC(&rango1,&rango2,&incremento);
}
}
char tipoConv(void){
char caract;
return caract;
}
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 6 of 16
int suma=*ran1,incremento=*inc,rango2=*ran2;
float conversion;
while(suma<=rango2){
conversion=(((suma)*9)/5)+32;
printf("\n%d §C ----------------------------- %.1f §F",suma,conversion);
suma=suma+incremento;
}
getch();
}
int suma=*ran1,incremento=*inc,rango2=*ran2;
int conversion;
while(suma<=rango2){
conversion=((suma-32)*5)/9;
printf("\n%d §F ----------------------------- %d §C",suma,conversion);
suma=suma+incremento;
}
getch();
}
Volver
Ejemplos de cadenas. Función que realiza la misma operación que la función atoi,
que convierte una cadena en un entero. La función regresa el entero representado
por la cadena s si se pudo convertir, en caso contrario regresa 0. Si la función
encuentra caracteres espacio o tabulación, los salta. Si al empezar la secuencia de
dígitos, ésta se interrumpe, el programa termina.
#include stdio.h
#include ctype.h
void main(void){
int n;
char cad[50];
clrscr();
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 7 of 16
while(1){
if(*s==' ' || *s=='\t'){
s++;
}
else break;
}
if(*s=='+'){
s++;
}
else if(*s=='-'){
signo=-1;
s++;
}
while(1){
if(*s=='\0' || !isdigit(*s)){
break;
}
num=10*num+(*s-'0');
s++;
}
return signo*num;
}
Volver
Ejemplos de cadenas. Función que realiza la misma operación que la función strlen.
Calcula la longitud de la cadena S. Regresa el número de caracteres en S sin contar
el caracter de fin de cadena.
#include stdio.h
#include ctype.h
void main(void){
int n;
char cad[50];
clrscr();
int c=0;
while(1){
if(*s=='\0'){
break;
}
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 8 of 16
c++;
s++;
}
return c;
}
Volver
if(strcmp(ps[np-1],"GUARDA")==0){
for(i=0,j=1;j<(np-1);i++,j++){
arreglo[i]=atoi(ps[j]);
printf("\n%d",arreglo[i]);
}
}
if(strcmp(ps[np-1],"LISTA")==0){
for(i=1;i<(np-1);i++){
puts(ps[i]);
}
}
Volver
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 9 of 16
printf("PROGRAMA QUE CALCULA UNA OPERACION ARITMETICA SIMPLE ENTRE DOS OPERANDOS");
printf("\n\nLa sintaxis es: Calcula operando operador operando");
printf("\n");
while(i<=narg){
printf("%s",sarg[i]);
i++;
}
op1=atof(sarg[1]);
op2=atof(sarg[3]);
if(strcmp(sarg[2],"+")==0)
resul=op1+op2;
else if(sarg[2][0]=='-')
resul=op1-op2;
else if(strcmp(sarg[2],"*")==0)
resul=op1*op2;
else if(sarg[2][0]=='/')
resul=op1/op2;
else{
printf("\nOperador invalido: '%s'",sarg[2]);
return;
}
printf("\n\nEl resultado es %.1f",resul);
getch();
Volver
void main(void){
char txt[30][50],opcion;
int llenas=0,max=30,actual;
while(1){
clrscr();
printf(" EDITOR DE TEXTO");
printf("\n SELECCIONA LA PRIMERA LETRA DE LA OPCION DESEADA");
printf("\n\nAgregar Salir Lista Reemplaza Inserta Opcion: ");
opcion=toupper(getch());
if(opcion=='S')
break;
if(opcion=='A')
agrega_linea(txt,&llenas,max,&actual);
if(opcion=='L')
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 10 of 16
lista(txt,&llenas);
if(opcion=='R')
reemplaza_linea(txt,llenas,&actual);
if(opcion=='I')
inserta(txt,&llenas,actual,max);
}
}
/**************************************************************************/
void agrega_linea(char t[][50],int *ll,int max,int *act){
if(*ll==max){
printf("\n\nMemoria insuficiente...");
return;
}
printf("\n\n>");
fflush(stdin);
gets(t[*ll]);
*ll=*ll+1;
*act=*ll;
}
/**************************************************************************/
int i=0;
printf("\n\n");
while(i<*ll){
puts(t[i]);
i++;
}
getch();
}
/**************************************************************************/
/**************************************************************************/
if(ll==0){
printf("\n\nNo existe informacion a reemplazar");
getch();
return;
}
modif_actual(act,ll);
if(*act==-1){
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 11 of 16
else{
/*************************************************************************/
if(act==-1){
printf("\n\nLa linea seleccionada no existe...");
getch();
}
else{
j=*ll-1;
while(j>=act-1){
strcpy(t[j+1],t[j]);
j--;
}
printf("\n\nInserta la nueva linea: ");
fflush(stdin);
gets(t[act-1]);
(*ll)++;
}
}
Volver
#include stdio.h
#include conio.h
#include ctype.h
#include string.h
#include stdlib.h
struct DIREC{
char nombre[35];
char tele[20];
} ;
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 12 of 16
void main(){
char opcion;
FILE *archivo;
archivo=fopen("TELE.DAT","rb+"); /* usar opción "wb+" para crear el archivo .DAT y despu
while(1){
clrscr();
textattr(6+5*5);
clrscr();
textcolor(YELLOW);
cprintf(" DIRECTORIO TELEFONICO");
printf("\n\n");
cprintf(" N");
printf("uevo");
textcolor(YELLOW);
cprintf(" L");
printf("ista");
textcolor(YELLOW);
cprintf(" B");
printf("aja");
textcolor(YELLOW);
cprintf(" C");
printf("onsulta");
textcolor(YELLOW);
cprintf(" O");
printf("rdena");
textcolor(YELLOW);
cprintf(" S");
printf("alir");
gotoxy(1,25);
printf(" *** PRESIONE LA LETRA RESALTADA PARA ESCOGER LA OPCION ***");
gotoxy(1,4);
opcion=toupper(getch());
if(opcion=='S')
break;
switch(opcion){
case 'N':{
lee(archivo);
break;
}
case 'L':{
imprime(archivo);
break;
}
case 'B':{
pack(archivo);
break;
}
case 'C':{
consulta2(archivo);
break;
}
case 'O':{
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 13 of 16
ordena(archivo);
break;
}
}
}
clrscr();
fclose(archivo);
normvideo();
clrscr();
}
/*********************************************************************/
if((c%2)!=0){
textattr(6+5*5);
/* textcolor(LIGHTGRAY);*/
printf("\n");
cprintf("%d.- %-30s %16s",c,reactivo.nombre,reactivo.tele);
normvideo();
}
else{
textattr(6+5*4);
/* textcolor(WHITE);*/
printf("\n");
cprintf("%d.- %-30s %16s",c,reactivo.nombre,reactivo.tele);
normvideo();
}
if(y==23){
getch();
y=0;
}
y++;
c++;
}
getch();
}
/*********************************************************************/
fflush(stdin);
printf("Nombre : ");strupr(gets(reactivo.nombre));
if(strlen(reactivo.nombre)<30){
if(busca_Clave2(a,reactivo.nombre)==0){
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 14 of 16
printf("Tel‚fono : ");gets(reactivo.tele);
fseek(a,0,SEEK_END);
fwrite(&reactivo,sizeof(struct DIREC),1,a);
}
else{
printf("\n\nYa existen esos datos!!!");
getch();
}
}
else{
printf("\n\nM ximo 25 letras por nombre...");
printf("\n\nEl programa puede da¤arse si repite este error!!!");
getch();
}
}
/*********************************************************************/
/*********************************************************************/
p=busca_Clave2(a,nombre);
if(p!=0){
fseek(a,(p-1)*sizeof(struct DIREC),SEEK_SET);
fread(&r,sizeof(struct DIREC),1,a);
printf("\n\n\n");
textcolor(LIGHTGRAY);
cprintf("NOMBRE TELEFONO");
normvideo();
printf("\n%-20s %30s",r.nombre,r.tele);
getch();
}
else{
printf("\n\nLa informaci¢n solicitada no existe ...");
getch();
}
}
/*********************************************************************/
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 15 of 16
s=0;
i=0;
while(1){
if(s>=j)
break;
r=temp[s];
fseek(a,i*sizeof(struct DIREC),SEEK_SET);
fwrite(&r,sizeof(struct DIREC),1,a);
s++;
i++;
}
printf("\n\nSus archivos han sido ordenados alfab‚ticamente...");
getch();
/*********************************************************************/
if(p!=0){
while(1){
fseek(a,i*sizeof(struct DIREC),SEEK_SET);
if(fread(&r,sizeof(struct DIREC),1,a)==0)
break;
if(strcmp(r.nombre,clave)!=0){
fseek(a,i*sizeof(struct DIREC),SEEK_SET);
fwrite(&r,sizeof(struct DIREC),1,t);
}
i++;
}
fclose(t);
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com
Programación en C Page 16 of 16
fclose(a);
remove("TELE.DAT");
rename("TMP.DAT","TELE.DAT");
t=fopen("TELE.DAT","rb+");
printf("\n\nLa informaci¢n solicitada ha sido dada de baja...");
getch();
return(t);
}
else{
printf("\n\nNo existe el nombre...");
getch();
}
return 0;
}
/*********************************************************************/
http://www.geocities.com/SiliconValley/8195/cprog.html 6/2/04
PDF created with pdfFactory trial version www.pdffactory.com