Está en la página 1de 36

1.

-/* REALIZAR UN PROGRAMA EN C QUE PERMITA MOSTRAR


LA TABLA DE MULTIPLICAR DE UN NUMERO CUALQUIERA*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
Int n, c=0, r;
do{
printf("\n Ingrese un numero para ver su tabla de multiplicar:\t");
scanf("%d",&n);
}while(n<=0);
do{
++c;
r=c*n;
printf("\n%d * %d\t =\t %d",n,c,r);
}while(c<12);
getch();
}

2.-/* REALIZAR UN PROGRAMA EN C QUE PERMITA MOSTRAR SI


UN NUMERO N ES PERFECTO O IMPERFECTO*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n, i, s, st=0;
printf("\nIngrese un numero:\t");
scanf("%d",&n);
for(i=1;i<n;i++)
{
if(n%i==0)
st+=i;
}
if(st==n)
{
printf("\nEl numero perfecto");
}
else
{
printf("\nEl no numero perfecto");
}
getch();
}
-1-

3.-/*DEL 1 AL 1000 DECIR CUALES SON PERFECTOS Y CUANTOS


HAY.*/
#include<stdio.h>
#include<conio.h>
main()
{int i,j,acum,r,c=0;
clrscr();
for(i=1;i<1000;i++)
{acum=0;
for(j=1;j<i;j++)
{r=i%j;
if(r==0)
acum+=j;
}
if(i==acum)
{printf("\n%d\n", i);
c++;
}
}
printf("\nHay %d numeros perfectos.", c);
getch();
return 0;
}

4.-/* REALIZAR UN PROGRAMA EN C QUE PERMITA MOSTRAR SI


EL PRIMER
NUMERO ES MAYOR QUE EL PRIMERO O SI SON IGUALES*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,n1;
do
{
printf("\nIngrese el primer numero:\t");
scanf("%d",&n);
printf("\nIngrese el segundo numero:\t");
scanf("%d",&n1);
-2-

}while(n<=0 || n1<=0);
if(n==n1)
{
printf("\nLos numeros son iguales");
}
else
if(n>n1)
{
printf("\nEl primer numero es mayor que el
segundo");
}
else
{
printf("\nEl segundo numero es mayor
que el primero");
}
getch();
}

5.-/*REALIZAR UN PROGRAMA EN C QUE PERMITA CALCULAR


EL PRODUCTO
DE UN NUMERO CUALQUIERA*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,n1,i,r=0;
do{
printf("\nIngrese el primer numero:\t");
scanf("%d",&n);
}while(n<=0);
do{
printf("\nIngrese el segundo numero:\t");
scanf("%d",&n1);
}while(n1<=0);
for(i=1; i<=n1;++i)
{
r=r+n;
-3-

}
printf("\nEl producto es:\t %d",r);
getch();
}
6.-/* REALIZAR UN PROGRAMA EN C QUE PERMITA CALCULAR
LA MEDIA DE UNA LISTA
DE NUMEROS ENTEROS Y MOSTRAR EL RESULTADO UNA VEZ*/
#include<stdio.h>
#include<conio.h>
void main()
{
int c,n,e,ac=0,m;
clrscr();
printf("ingrese la cantidad de numeros:");
scanf("%d",&n);
for(c=1; c<=n; ++c)
{
printf("\n\nIngrese el numero emtero:");
scanf("%d",&e);
ac=ac+e;
}
m=ac/n;
printf("\n\nLa media es:%d",m);
getch();
}

7.-/*PEDIR UN NUMERO N POR TECLADO Y PRESENTAR LOS


PRIMEROS NMEROS DE LA SERIE DE FIBONACI*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,n;
printf("Ingrese los elementos a mostrar en la serie:");
scanf("%d",&n);
a=0;
b=1;
for(int i=1;i<=n;i++)
{
printf("\n%d\t",a);
a=a+b;
b=a-b;
}
getch();
-4-

8.-/*EJEMPLO 1 DEL #7*/


#include <stdio.h>
#include <conio.h>
Void suma1 ( );
Void main ( )
{
Clrscr( );
suma1 ( );
getch( );
}
Void suma1 ( )
{
Int a,b,r;
printf(\d Ingrese el primer numero:\t);
printf(\d Ingrese el primer numero:\t);
scanf(%d,&a);
scanf(%d,&b);
r=a+b;
printf(\n\n La suma de %d + %d es = %d,a,b,r);
getch();
}
9.-/*EJEMPLO 2 DEL #7*/
#include <stdio.h>
#include <conio.h>
Void suma2 (int , int );
Void main ( )
{
Clrscr( );
Int a,b,r;
printf(\d Ingrese el primer numero:\t);
printf(\d Ingrese el primer numero:\t);
scanf(%d,&a);
scanf(%d,&b);
suma2 (a+b);
getch( );
}
Void suma2 (int x, int y)
{
printf(\n\n La suma de %d + %d es = %d,a, b, x+y);
getch( );
}
-5-

10.-/*EJEMPLO 3 DEL #7*/


#include <stdio.h>
#include <conio.h>
int suma3 ( );
Void main ( )
{
Clrscr( );
r=suma3 ( );
printf(\n\n La suma de %d + %d es = %d,a, b,r);
getch( );
}
int suma3 ( )
{
Int a,b,r;
printf(\d Ingrese el primer numero:\t);
printf(\d Ingrese el primer numero:\t);
scanf(%d,&a);
scanf(%d,&b);
return (a+b);
}

11.-/*EJEMPLO 4 DEL #7*/


#include <stdio.h>
#include <conio.h>
int suma3 ( );
Void main ( )
{
Clrscr( );
Int a,b,r;
printf(\d Ingrese el primer numero:\t);
printf(\d Ingrese el primer numero:\t);
scanf(%d,&a);
scanf(%d,&b);
printf(\n\n La suma de %d + %d es = %d,a, b,suma 4 (a, b));
getch( );
}
int suma4 (int x, int y )
{
return (x+y);
-6-

12.-/* PASO POR REFERENCIA. */


#include<stdio.h>
void intercambio(int *,int *);
main() /* Intercambio de valores */
{
int a=1,b=2;
printf("a=%d y b=%d",a,b);
intercambio(&a,&b); /* llamada */
printf("a=%d y b=%d",a,b);
}
void intercambio (int *x,int *y)
{
int aux;
aux=*x;
*x=*y;
*y=aux;
printf("a=%d y b=%d",*x,*y);
}

13.-/* DECLARACION DE UN ARRAY. */


#include <stdio.h>
#include <conio.h>
Void main() /* Rellenamos del 0 - 9 */
{
int vector[10],i;
for (i=0;i<10;i++) vector[i]=i;
for (i=0;i<10;i++) printf(" %d",vector[i]);
getch ( );
}

14.-/*DELARACION DE UN VECTOR TIPO CHAR*/


#include<stdio.h>
#include<conio.h>
void main()
{
-7-

clrscr();
char cadena[20];
int i;
for(i=0;i<19;i++)
cadena[i]=getche();
cadena[i]='\0';
printf("\n%s",cadena);
getch();
}

15.-/*REALIZAR UN PROGRMA
CARACTERES DESEADOS
HASTA QUE SE DE UN ENTER*/

EN

QUE

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char cadena[20];
int i;
for(i=0;i<19 && cadena[i-1]!=13;i++)
cadena[i]=getche();
cadena[i]='\0';
if(i==19)cadena[i]='\0';
printf("\n%s",cadena);
getch();
}

16.-/* MATRIZ BIDIMENSIONAL. */


#include <stdio.h>
main() /* Rellenamos una matriz */
{
int x,i,numeros[3][4];
/* rellenamos la matriz */
for (x=0;x<3;x++)
for (i=0;i<4;i++)
scanf("%d",&numeros[x][i]);
/* visualizamos la matriz */
for (x=0;x<3;x++)
for (i=0;i<4;i++)
-8-

MUESTRE

LOS

printf("%d",numeros[x][i]);
}

17.-/*LEER UNA CADENA DE CARACTERES Y CAMBIAR LA


MAYUSCULAS POR MINUSCULAS
Y LAS MINUSCULAS POR MAYUSCULAS Y DIGITOS POR
PUNTOS*/
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void modificar();
char cad[30];
void main()
{
clrscr();
printf("\nIngrese una cadena de caracteres:\t");
gets(cad);
printf("\n\n");
modificar();
puts(cad);
printf("\n\n");
getch();
}
void modificar()
{
int i;
for(i=0;cad[i]!='\0';i++)
{
if(isupper(cad[i]))
cad[i]=tolower(cad[i]);
else if(islower(cad[i]))
cad[i]=toupper(cad[i]);
else if(isdigit(cad[i]))
cad[i]='.';
}
}

18.-/*REALIZAR UN PROGRAMA QUE SEPARE LOS BLANCOS DE


LAS PALABRAS Y
LOS PRESENTE*/

-9-

#include<stdio.h>
#include<conio.h>
void escribe(char[]);
void main()
{
clrscr();
char frase[50];
printf("\nIngrese una cadena de caracteres:\t");
gets(frase);
escribe(frase);
getch();
}
void escribe(char frase[])
{
char palabra[15];
int j=0,i=0;
while(frase[i]!='\0')
{
while(frase[i]==' ')
i++;
j=0;
while((frase[i]!=' ')&&(frase[i]!='\0'))
{
palabra[j++]=frase[i++];
palabra[j]='\0';
printf("\n");
puts(palabra);
}
}
}

19.- /*SUMA DE MATRICES*/


#include <stdio.h>
#include <conio.h>
int a[3][3];
int b[3][3];
int c[3][3];
int i,j,fila,colum;
void main()
{
clrscr();
void ingreso();
-10-

void salida();
gotoxy(25,2);printf("Suma de Matrices");
gotoxy(1,4);printf("ingrese filas:");scanf("%d",&fila);
printf("\ningrese columnas:");scanf("%d",&colum);
printf("\n\tLLenar matrices:");
a[fila][colum];
b[fila][colum];
c[fila][colum];
ingreso();
salida();
getch();
}
void ingreso()
{
for (i=0;i<fila;i++)
for (j=0;j<colum;j++){
gotoxy(3+j*4,14+i);
scanf("%d",&a[i][j]);
}
gotoxy(15,15);printf("+");
for (i=0;i<fila;i++)
for (j=0;j<colum;j++){
gotoxy(20+j*4,14+i);
scanf("%d",&b[i][j]);
}
}
void salida()
{
gotoxy(35,15);printf("=");
for (i=0;i<fila;i++)
for (j=0;j<colum;j++){
c[i][j]=a[i][j]+b[i][j];
gotoxy(40+j*4,14+i);
printf("%d",c[i][j]);

-11-

}
}

20.- /*LLENAR UN ARREGLO Y EN OTRO ARREGLO MOSTRAR EL


ORDEN INVERSO*/
#include<stdio.h>
#include<conio.h>
main()
{ clrscr();
int a[6];
int b[6];
int c=0,i=0;
gotoxy(10,2);printf("LLenar el arreglo de 6 elementos");
gotoxy(8,4);printf("Arreglo1");
for(i=0;i<=5;i++)
{ gotoxy(10,i+5);
scanf("%d",&a[i]);
}
for (i=5;i>=0;i--)
{ b[c]=a[i];
c++;
}
gotoxy(23,4);printf("Arreglo2");
for (i=0;i<=5;i++){
gotoxy(25,i+5);printf("%d",b[i]);
}

getch();
return(0);
}

-12-

21.-/*MULTIPLICACION MEDIANTE SUMAS SUCESIVAS*/


#include<conio.h>
#include<stdio.h>
int n,x;
int suma(int n);
void main()
{
clrscr();
gotoxy(28,3);printf("...SUMATORIA...");
printf("\n\n\n\n\tingresar el valor de X:");
scanf("%d",&x);
printf("\n\n\tingresar el valor de N:");
scanf("%d",&n);
gotoxy(25,20);printf("La Sumatoria es: %d", suma(n));
getch();
}
int suma(int n)
{
if(n<=1)
return(x);
else
return(x+(suma(n-1)));
}

22.-/*CERACION DE LIBRERIA*/
#ifndef libreria_h
#define libreria_h
double suma(double n1, double n2)
{
double s=0;
s=n1+n2;

-13-

return (s);
}
#endif

23.-/* LLAMADA DE LA LIBRERIA ANTERIOR*/


#include<stdio.h>
#include<conio.h>
#include "c:libreria.h"
double n1,n2,sum;
void main()
{
clrscr();
printf("\n\t\tprobando funcion SUMA\n\n");
printf("\tIngrese num1:");scanf("%d",&n1);
printf("\n\tIngrese num2:");scanf("%d",&n2);
sum=suma(n1,n2);
printf("\n\tresultado= %d ",sum);

getch();
}

24.-/*LANZAMIENTO DE DADO ALEATORIO #1*/


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main()
{ int x,n,c,a=0,b=0,d=0,f=0,g=0,e=0;
srand(time(NULL));
for(x=1;x<=1000;x++)
{
n=random(6)+1;
/*printf("%d",n);*/

-14-

switch (n)
{
case 1:
a=a+1;
break;
case 2:
b=b+1;
break;
case 3:
d=d+1;
break;
case 4:
e=e+1;
break;
case 5:
f=f+1;
break;
case 6:
g=g+1;
break;
}
}
printf("\n\nEl uno salio:%d",a);
printf("\n\nEl dos salio:%d",b);
printf("\n\El tres salio:%d",d);
printf("\n\nEl cuatro salio:%d",e);
printf("\n\nEl cinco salio:%d",f);
printf("\n\nEl seis salio:%d",g);
getch();
}

25.- /*LANZAMIENTO DE DADO ALEATORIO #2*/


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main()
{ int x,n,c,a=0,b=0,d=0,f=0,g=0,e=0;
for(x=1;x<=1000;x++)
{
n=random(6)+1;
/*printf("%d",n);*/

-15-

switch (n)
{
case 1:
a=a+1;
break;
case 2:
b=b+1;
break;
case 3:
d=d+1;
break;
case 4:
e=e+1;
break;
case 5:
f=f+1;
break;
case 6:
g=g+1;
break;
}
}
printf("\n\nEl uno salio:%d",a);
printf("\n\nEl dos salio:%d",b);
printf("\n\El tres salio:%d",d);
printf("\n\nEl cuatro salio:%d",e);
printf("\n\nEl cinco salio:%d",f);
printf("\n\nEl seis salio:%d",g);
getch();
}

26.-/*TORRES DE HANOI*/
#include<stdio.h>
#include<conio.h>
int mover(int,char,char,char);
void main()
{
clrscr();
int ndiscos,movimientos;
-16-

gotoxy(25,2);printf("...BIENVENIDO A LAS TORRES DE HANOI...");


printf("\n\n\t\t***Numero de discos:");
scanf("%d",&ndiscos);
movimientos=mover(ndiscos,'I','C','D');
printf("\n\nMovimientos efectuados:%d\n",movimientos);
getch();
}
int mover(int ndiscos,char i,char c,char d)
{
int movimientos=0;
if(ndiscos>0)
{
mover(ndiscos-1,i,d,c);
printf("\n\t*mover disco %d de %c a %c\n",ndiscos,i,d);
movimientos++;
mover(ndiscos-1,c,i,d);
}
return(movimientos);
}

27.- /*INGRESE NUMERO DE ELEMENTOS DE SERIE FIBONACCI


#1*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,n;
printf("Ingrese los elementos a mostrar en la serie:");
scanf("%d",&n);
a=0;
b=1;
for(int i=1;i<=n;i++)
{
printf("\n%d\t",a);
a=a+b;
b=a-b;
-17-

}
getch();
}

28.- /*COPIA LA CADENAS*/


#include
#include
#include
#include

<iostream.h>
<stdio.h>
<conio.h>
<stdlib.h>

char cad1[50];
char cad2[50];
void copyString(int n)
{
if(cad1[n]!=NULL)
{
cad2[n]=cad1[n];
copyString(n+1);
}
}
void main()
{
clrscr();
printf("CADENA: ");
gets(cad1);
copyString(0);
puts(cad2);
getch();
}

29.- /*CADENAS GUARDADAS EN UN TERCER ARREGLO*/


#include
#include
#include
#include

<iostream.h>
<stdio.h>
<conio.h>
<stdlib.h>

char cad1[50];
char cad2[50];
char cad3[100];

-18-

void concatStr(int n, int nn)


{
if(cad1[n]==NULL)
{
if(cad2[nn]!=NULL)
{
cad3[n]=cad2[nn];
concatStr(n+1,nn+1);
}
}
else
{
cad3[n]=cad1[n];
concatStr(n+1,nn);
}
}
void main()
{
clrscr();
printf("CADENA [1]: ");
gets(cad1);
printf("CADENA [2]: ");
gets(cad2);
concatStr(0,0);
printf("\nCADENAS CONCATENADAS EN UN TERCER ARREGLO:\n\n");
puts(cad3);
getch();
}

30.-/*DECIMAL A BINARIO*/
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
long int cambase(int);
int prueba(long int);
int a, b;
long int can;
void main()
{
int x;
do
{
clrscr();
-19-

printf("\n\n\n\t\t CAMBIO DE BASE \N ");


printf("\n\n\n Ingrese el Numero: ");scanf("%d",&a);
can=cambase(a);
printf("\n \n\nEl numero %d en base 2 es: %ld", a,can);
printf("\n\n\n Desea utilizarlo nuevamente: (Si=1 // No=0....)");
scanf("%i",x);
}
while(x!=0);
getch();
}
int prueba(long int nu)
{
int re,cont=0;
do
{
re=nu%10;
if(re>=2)
cont++;
nu=((nu-re)/10);
}
while(nu>=2);
return(cont);
}
long int cambase(int nu)
{
long int cc=0;
int co=0,re;
do
{
cc++;
re=prueba(cc);
if(re==0)
co++;
}
while((co<nu));
return(cc);
}

-20-

31.-/*2.- CARGAR UN ARRAY DE M NMEROS ENTEROS DECIR


CUAL ES EL MAYOR Y DONDE esta. */
#include<stdio.h>
#include<conio.h>
int a[5];
int i=0,sp=0,si=0,c=0,m=0,mayor=0,posic=0;
main()
{ clrscr();
printf("Ingrese el tamao del array: ");scanf("%d",&m);
printf("\n\t\tIngrese los valores del array\n\n");
a[m];
for (i=0;i<m;i++){
do{
printf("Array[%d]:",i);
scanf("%d",&a[i]);}
while (a[i]<0);
}
mayor=a[0];
posic=0;
for (i=1;i<m;i++)
{ if (a[i]>mayor){
mayor=a[i];
posic=i;
}
}
//presentacion de resultados
printf("\n El numero mayor es: %d",mayor);
printf("\n Esta en la poscion: %d",posic);
getch();
return(0);
}

32.-/*CARGAR UN ARRAY DE N ENTEROS Y CALCULAR EL


PROMEDIO DE LOS QUE ESTN EN POSICIONES PARES.*/
#include<stdio.h>
#include<conio.h>
int a[5];
-21-

int i=0,sp=0,c=0,m=0,mayor=0,posic=0;
float prom=0;
main()
{ clrscr();
// printf("Ingrese el tamao del array: ");scanf("%d",&m);
printf("\n\t\tIngrese los valores del array\n\n");
a[10];
for (i=0;i<10;i++){
do{
printf("Array[%d]:",i);
scanf("%d",&a[i]);}
while (a[i]<0);
}

for (i=0;i<10;i++)
{
if ((i%2)==0){
sp=sp+a[i];
c++;
}
}
prom=sp/c;
//presentacion de resultados
printf("\n\nla sumatoria es:%d",sp);
printf("\nnumero de posiciones pares:%d",c);
printf("\n\n\t El promedio de los que estan en posiciones pares es:
%.2f",prom);
getch();
return(0);
}

33.-/*LEER EN LA FUNCIN MAIN() UN NMERO ENTERO "N"


MAYOR
QUE
2
Y
MENOR
O
IGUAL
QUE
20.
CARGAR, EN UNA FUNCIN, UN ARRAY DE "N" NMEROS
ENTEROS. MOSTRAR EL VECTOR, EN UNA SOLA LNEA, EN
OTRA
FUNCIN.
EN MAIN() LEER OTRO NMERO ENTERO Y EN UNA FUNCIN
-22-

CONTAR LAS VECES QUE APARECE DICHO NMERO EN EL


ARRAY, EL RESULTADO DEBE INDICARSE EN MAIN().*/
#include<stdio.h>
#include<conio.h>
void fun_array(int n);
int fun_contar(int num, int n);
int a[18];
int i=0,n=0,num=0,c=0,result=0;
void main()
{ clrscr();
printf("\nIngrese un numero:");
do
scanf("%d",&n);
while ( n<2 || n>20);
printf("\n\n\t\tIngresar datos en el array\n");
fun_array(n);
printf("\ningrese numero:");
do
scanf("%d",&num);
while(num<0);
result=fun_contar(num,n);
printf("\n\n\tEl numero-- %d --aparece en el array,-- %d --numero de
veces",num,result);
getch();
}
void fun_array(int n)
{
a[n];
for (i=0;i<n;i++){
do{
printf("Array[%d]:",i);
scanf("%d",&a[i]);}
while (a[i]<0);
}
}
int fun_contar(int num, int n)
{
a[n];
-23-

for (i=0;i<n;i++)
{ if (a[i]==num){
c++;
}
}
return(c);
}

34.-/* LEER, EN MAIN(), UNA CADENA DE CARACTERES Y


LLAMAR A UN FUNCIN QUE LA MODIFIQUE. EN LA FUNCIN
SE DEBEN CAMBIAR MAYSCULAS POR MINSCULAS,
MINSCULAS POR MAYSCULAS Y DGITOS POR PUNTOS. EL
RESULTADO SE ESCRIBE EN LA FUNCIN MAIN(). */
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void modificar();
char cad[30];
void main()
{ clrscr();
printf("ingrese una cadena de caracteres:");
gets(cad);
modificar();
puts(cad);
getch();
}

void modificar()
{
int i;
for (i=0;cad[i]!='\0';i++)
{
if (isupper(cad[30]))
cad[i]=tolower(cad[i]);
else
if (islower(cad[i]))
cad[i]=toupper(cad[i]);
else
if (isdigit(cad[i] ))

-24-

cad[i]='.';
}
}

35.-/* LEER UNA CADENA DE CARACTERES Y CORTARLA EN


PALABRAS ESCRIBIENDO CADA PALABRA EN UNA LNEA. SE
SUPONE QUE LAS PALABRAS SE SEPARAN SLO POR
BLANCOS.*/
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
void escribe(char[]);
void main()
{ clrscr();
char frase[50];
printf("ingrese una cadena de caracteres:");
gets(frase);
void escribe(frase);
getch();
}
void escribe (char frase[])
{
char palabras[15];
int i=0,j=0;
while (frase[i]!='\0')
{
while (frase[i]==' ')
i++;
j=0;
while {
((frase[i]!=' ')&&(frase[i]!='\');
palabra[j++]=frase[i++];
palabra[j]='\0';
puts(palabra);
}
}
}
}
-25-

36.-/* COMO MODIFICAR UNA CADENA DE CARACTERES*/


#include <stdio.h>
#include<conio.h>
#include<ctype.h>
void modificar();
char cad[30];
void main()
{
printf("ingrese una cadena de caracteres:");
gets(cad);
modificar();
puts(cad);
getch();
}
void modificar()
{ int i;
for(i=0;cad[i]!='\0';i++)
{
if (isupper(cad[i]))
cad[i]= tolower(cad[i]);
else if(islower(cad[i]))
cad[i]=toupper(cad[i]);
else if (isdigit(cad[i]))
cad[i]= '.';
}
}

37.-/* GENERAR LOS N PRIMEROS TRMINOS DE LA SERIE DE


FIBONACCI.-*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,n;
printf("Ingrese los elementos a mostrar en la serie:");
scanf("%d",&n);
a=0;
b=1;
for(int i=1;i<=n;i++)
{
-26-

printf("\n%d\t",a);
a=a+b;
b=a-b;
}
getch();
}

38.-/*CAMBIO DE BASE POR RECURSIVIDAD*/


#include<stdio.h>
#include<conio.h>
#include<math.h>
unsigned long binario(int,int);
void main()
{
int num;
clrscr();
printf("ingrese numero");
scanf("%d",&num);
printf("el binario es %d es %d", num, binario(num,0));
getch();
}
unsigned long binario (int n, int pot)
{
int residuo,divisor;
if (n<2)
return n*pow10(pot);
else
{
residuo=n%2;
divisor=n/2;
return ((residuo*pow10(pot))+ binario(divisor,pot+1));
}
}

39.-/*FACTORIAL*/
#include<conio.h>
#include<stdio.h>
int lee_numero();
int factorial(int x);
-27-

void main()
{
int n,i,resp();
n=lee_numero();
do
{
i=lee_numero();
}while (n<=i);
resp= (factorial(n)/factorial(n)*(factorial(n-i)));
printf("%d",resp);
}
getch();
int lee_num();
{
int x;
do
{
print("ingrse un numero");
scanf("%d",&x);
}while (x<0);
return x;
}
int factorial(int x);
{Int j,f=1;
For (j=1;j<=x;j++)
{
f*=j;
}
Return (F);
}

40.- /*MLTIPLO DE NUEVE*/


#include<stdio.h>
#include<conio.h>
void main()
{
Clrscr ();
Int n=0, r=0, s=0, x=0;
Printf ("ingrese un numero para verificar si es mltiplo de 9:");
Scanf ("%d", &n);
x=n;
-28-

Do
{
if(s>9)
{
n=s;
s=0;
} while (n! =0)
Do
{
r=n%10;
n=n/10;
s+=r;
}while (s<9);
if(s==9)
printf("es multiplo de 9:%d",x);
else
printf("no es multiplo de 9:%d",x);
getch();
}

41.-/*AGENDA1*/
#include<dos.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
//declaracion de funciones
void
void
void
void

ingreso_datos();
visualizar();
buscar();
modificar();

//estructura de la agenda
struct agenda
{ char nombre[30];
char telefono[10];
char direccion[30];
-29-

char email[20];
char cumple[20];
}amigo[4];
void main ()
{
//declaracion de variables
int op;
//menu
do
{ clrscr();
gotoxy(30,20); printf("****AGENDA****");
gotoxy(30,21); printf("1.-Ingresar");
gotoxy(30,22); printf("2.-Ver agenda ");
gotoxy(30,23); printf("3.-Buscar amigo");
gotoxy(30,24); printf("4.-Modificar");
gotoxy(30,25); printf("5.-Salir");
gotoxy(30,26); printf("Ingresar opcion:");
scanf("%d",&op);
switch(op)
{ case 1:ingreso_datos();
break;
case 2:visualizar();
break;
case 3:buscar();
break;
case 4:modificar();
break;
}
}while(op!=5);
getch();
}
//funciones
int indice=0;
void ingreso_datos()
{ clrscr();
int i=0;
gotoxy(4,6);printf("Nombre");
gotoxy(20,6);printf("Direccion");
gotoxy(40,6);printf("Telefono");
-30-

gotoxy(54,6);printf("Fecha_nac");
gotoxy(69,6);printf("E-MAIL");
if(indice<=3)
{
gotoxy(4,(i*2)+8);scanf("%s",&amigo[indice].nombre);
gotoxy(20,(i*2)+8);scanf("%s",&amigo[indice].direccion);
gotoxy(40,(i*2)+8);scanf("%s",&amigo[indice].telefono);
gotoxy(54,(i*2)+8);scanf("%s",&amigo[indice].cumple);
gotoxy(69,(i*2)+8);scanf("%s",&amigo[indice].email);
indice++;i++;
}
else
{ gotoxy(20,20);printf("MEMORIA LLENA");
}
getch();
}
void visualizar()
{ clrscr();
gotoxy(4,6);printf("Nombre");
gotoxy(20,6);printf("Direccion");
gotoxy(40,6);printf("Telefono");
gotoxy(54,6);printf("Fecha_nac");
gotoxy(69,6);printf("E-MAIL");
for(int i=0;i<=indice;i++)
{ gotoxy(4,i+8); printf("%s",amigo[i].nombre);
gotoxy(20,i+8); printf("%s",amigo[i].direccion);
gotoxy(40,i+8); printf("%s",amigo[i].telefono);
gotoxy(54,i+8); printf("%s",amigo[i].cumple);
gotoxy(69,i+8); printf("%s",amigo[i].email);
}
getch();
}
void buscar()
{ clrscr();
int i;
char nom[10];
printf("Ingrese el nombre que desea buscar:");
scanf("%s",&nom);
gotoxy(4,6);printf("Nombre");
gotoxy(20,6);printf("Direccion");
-31-

gotoxy(40,6);printf("Telefono");
gotoxy(54,6);printf("Fecha_nac");
gotoxy(69,6);printf("E-MAIL");
for(i=0;i<=indice;i++)
{ if(strcmp(nom,amigo[i].nombre)==0)
{ gotoxy(4,i+8); printf("%s",amigo[i].nombre);
gotoxy(20,i+8); printf("%s",amigo[i].direccion);
gotoxy(40,i+8); printf("%s",amigo[i].telefono);
gotoxy(54,i+8); printf("%s",amigo[i].cumple);
gotoxy(69,i+8); printf("%s",amigo[i].email);
}
}
getch();
}
void modificar()
{clrscr();
char modi[10];
printf("Ingrese lo que desea modificar\n");
scanf("%s",&modi);
gotoxy(4,6);printf("Nombre");
gotoxy(20,6);printf("Direccion");
gotoxy(40,6);printf("Telefono");
gotoxy(54,6);printf("Fecha_nac");
gotoxy(69,6);printf("E-MAIL");
for(int i=0;i<=indice;i++)
{ if(strcmp(modi,amigo[i].nombre)==0)
{ gotoxy(20,i+8);scanf("%s",&amigo[i].direccion);
gotoxy(40,i+8); scanf("%s",&amigo[i].telefono);
gotoxy(69,i+8); scanf("%s",&amigo[i].email);
}
}
getch();
}

42.-/*AGENDA2*/
-32-

/* crear una agenda personal que lleve nuevo, consulta, modificacin,


mostrar todo, eliminar, salir de la agenda*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
typedef struct
{ char nombre[40];
char ciudad[20];
char direccion[50];
char telefono[10];
char email[20];
}agenda;
agenda contacto[50];
int indice=0;
int busqueda(char[40]);
void ingreso();
void consulta(int);
void modificar(int);
void eliminar(int);
// void reporte();
void menu();
void evalua_opcion(int);
void main()
{
textbackground(BLUE);
menu();}
void menu()
{int opcion;
do
{ clrscr();
gotoxy(30,2);printf("***********");
textcolor(BROWN);
gotoxy(30,3);cprintf(" | MENU |");
gotoxy(30,4);printf("***********");
printf("\n\n1._nuevo contacto");
printf("\n2._consulta de un contacto");
printf("\n3:_modifica un contacto");
printf("\n4._elimina un contacto");
printf("\n5._lista de contacto");
printf("\n6._salir de la agenda");
printf("\n\n opcion:");
scanf("%d",&opcion);
evalua_opcion(opcion);
}while(opcion!=6);
-33-

}
void evalua_opcion(int op)
{ char nom[40];
switch(op)
{case 1:textbackground(BLUE);
ingreso();
break;
case 2: clrscr();
printf("nombre a consultar:");
scanf("%s",nom);
consulta (busqueda(nom));
getch();
break;
case 3:
clrscr();
printf("nombre a modificar:");
scanf("%s",nom);
modificar(busqueda(nom));
getch();
break;
case 4:
clrscr();
printf("Nombre a eliminar:");
scanf("%s",nom);
eliminar(busqueda(nom));
getch();
break;
case 5:
clrscr();
for(int i=0;i<=indice-1;i++);
{ consulta(i);}
getch();
break;
case 6:
clrscr();
printf("salida");
break;
default:
clrscr();
printf("opcion incorrecta");
}
}
int busqueda(char nom[40])
{ int posicion=100;
for(int i=0;i<=indice-1;i++)
{ if(strcmp(contacto[i].nombre,nom)==0)
posicion=i;
}
return posicion;
}
-34-

void ingreso()
{clrscr();
printf("\n Nombre:");
scanf("%s",contacto[indice].nombre);
printf("\n Ciudad:");
scanf("%s",contacto[indice].ciudad);
printf("\n Direccion:");
scanf("%s",contacto[indice].direccion);
printf("\n Telefono:");
scanf("%s",contacto[indice].telefono);
printf("\n Email:");
scanf("%s",contacto[indice].email);
indice++;
}
void consulta(int posicion)
{
printf("%s %s %s %s
%s",contacto[posicion].nombre,contacto[posicion].ciudad,contacto[po
sicion].direccion,contacto[posicion].telefono,contacto[posicion].email)
;
getch();
}
void modificar(int posicion)
{ char band;
printf("\ndesea modificar la direccion[s/n]:");
scanf("%c",&band);
if(band=='S'||band=='s')
printf("\nnueva direccion:");
scanf("%s",contacto[posicion].direccion);
printf("\n\ndesea modificar el telefono[s/n]:");
scanf("%c",&band);
if(band=='S'||band=='s')
printf("nuevo telefono:");
scanf("%s",contacto[posicion].telefono);
printf("\n\ndesea modificar el email[s/n]:");
scanf("%c",&band);
if(band=='S'||band=='s')
printf("nuevo email:");
scanf("%s",contacto[posicion].email);
getch();
}
void eliminar(int posicion)
{ if(posicion!=indice-1)
{ for(int i=posicion+1;i<=indice-1;i++)
{ strcpy(contacto[i-1].nombre,contacto[i].nombre);
strcpy(contacto[i-1].ciudad,contacto[i].ciudad);
strcpy(contacto[i-1].direccion,contacto[i].direccion);
strcpy(contacto[i-1].telefono,contacto[i].telefono);
-35-

strcpy(contacto[i-1].email,contacto[i].email);
}
}
indice--;
}

-36-

También podría gustarte