Red de conocimiento informático - Conocimiento del nombre de dominio - Cómo programar es divertido

Cómo programar es divertido

Hanoi

# include & ltgraphics.h & gt

# include & ltstdio.h & gt

void move _ step();

void hanoi_tower();

void init_hanoi_tower().

int m, n, mark = 1;

int w[3]={0, 0, 0};

Tamaño int sin signo

p>

void *buf, *buf1, *buf 2;

void main()

{int driver=VGA, modo = 2;

init gráfico(&driver&mode, "c:\\TC");

setbkcolor(0);

establecer color(15);

setfillstyle(1 ,7);

clear device();

printf("El número de discos es:");

scanf ("% d ", & ampm); if (m & lt1 | | m & gt; 10) exit (0);

printf ("El modo de disco móvil es:

scanf("%); d",&mark); if(mark>3||mark<1) export(0);

w[0]= m;

init_hanoi_tower(m);

hanoi_tower(m, 'A', 'B', 'C');

getchar();

closegraph();

}

/************************************ ******** *******/

void inicialization_Hanoi_Tower (int m)

{ int I;

setfillstyle(1, 7);

setviewport(100, 80, 540, 300, 1);

Rellenar (1, 1, 7); >Barra(40, 160, 120, 170); Barra(180, 160, 260, 170); Barra(320, 160, 400, 170); ); Barra(215, 17, 225, 159); Barra(355, 17, 365, 159); p>{setfillstyle(1, (8+I)% 16);

bar(75-i*5, 17+i* 3, 85+i*5, 27+I * 13);

}

settextstyle(0, 0, 2);

outtextxy(80- 8,175, "A");

outtextxy (220-8,175,"B");

outtextxy(360-8,175,"C");

tamaño=tamañoimagen(25,17,135,27);

buf 1 =(void *)malloc(tamaño);

getimage(1425,17,14135,27,buf 1);

buf 2 =(void *)malloc(tamaño);

getinmage(25,4,135,14,buf 2);

buf =(void *)malloc(tamaño);

}

/****************** ********************** **************/

void hanoi_tower(int m, char one, chartwo, char three)

{if(m=

=1)move_step(uno, tres);

else{hanoi_tower(m-1, uno, tres, dos);

move_stept(uno, tres);

Torre_Hanoi (m-1, dos, uno, tres);

}

}

/******** ** *****************************************/

nulo move_step(char getone, char putone)

{void *buf3, buf4

char c[7];

int i, j, k, x, y;

Unsigned int s,ss;

Interruptor (dos en uno)

{

Caso "a": k = 11-w[0]; x = 0; w[0]-; romper;

Caso "b": k = 11-w[1]; >Caso "c":k = 11-w[2];x = 280w[2]-;Descanso;

}

getimage(25+x, 17+k* 13, 135+x, 27+k*13, buf);

putimage(25+x, 17+k*13, buf1, COPY _ PUT) ;

if ( mark==3)

{ for(k-;k>=0;k-)

{putimage(25+x ,17+k*13,buf1,COPY_PUT);

for(I = 0;i<32767;i++)for(j = 0j<1000;j++);

putimage(25+x, 17+k*13, buf1, COPY _ PUT);

}

putimage(25+x, 4, buf, COPY _ PUT) );

if(putone = = ' A ' )k = 25;

si no(putone = = ' B ')k = 25+140;

si no k = 25+280;

si (x & lt;k)

for(y = x+20;y & ltk-20;y+=20)

{putimage(25+y-20, 4, buf2, COPY _ PUT);

putimage(25+y, 4, buf, COPY _ PUT

for(I = 0;i<32767;i++)for(j =); 0j<1000;j++);

}

for(y = x-20 ;y>= k;y-=20)

{putimage(25 +y-20, 4, buf2, COPY _ PUT);

putimage(25+y, 4,buf,COPY_PUT);

for(I = 0;i<32767;i++ )for(j = 0j<1000;j++);

}

}

Interruptor (botón)

{Caso "a ": k = 10-w[0]; x = 0; w[0]-; Romper;

Caso "b": k = 10-w[1]; x = 140; w[ 1]-; Descanso;

Caso "c": k = 10 -w[2];x=280w[2]-;descanso;

}

if(marca==3)

putimage(25+x ,4,buf2,COPY_PUT);

for(

y = 0; y & ltk-1; y++)

{putimage(25+x, 17+y*13, buf, COPY _ PUT); 0;i<32767;i++)for(j=0j<1000;j++);

putimage(25+x,17+y*13,buf1,COPY_PUT);

}

}

putimage(25+x, 17+k*13, buf, COPY _ PUT

set color(15); 0, 0);

setviewport (0, 320, 639, 479, 1);

If (n==0)

{ if(m); <10){ c[0]= m % 148; c[1]= m % 148; c[2]= ' \ 0 '; ");outtext(c);

outtext(" diskers:");

}

k = n+ 1;

ss=imagersize(31*8,0,31*8+31,14);

buf 4 =(void *)malloc(ss);

getimage(31*8 , 031*8+31, 14, buf 4);

if(k & lt; 10)

{ c[0]= k+48; ' \ 0 ';

}

si no(k & lt; 100){ c[0]= k/148; c[1]= k % 1 48; c[2]= '\ 0 '; }

si(k & lt; 1000){ c[0]= k/1048; k % = 100; = K/148;

c[2]= k % 148; c[3]= '\0';}

si no { c[0]= k/10048; k% = 1000; c[1]= k/1048; k% = 100; c[2]= k/148; /p>

c[4]= '\0';}

putimage(31*8, 0buf4, XOR_PUT);

outtextxy(31*8,0, c);

Gratis(buf 4);

/****************** ******** ***********************************/

c[0]= getone=='A'? 'A':getone=='B'? b ':' C ';

c[1]= '-'; c[2]= '-'; c[3]= '-'; ;c[6]= '\ 0 '; c[5]=putone=='A '? 'A':putone=='B'? b':'C';

x = n % 8 * 80

y = 8/8 * 15+15;

si(n/8 & gt;=10)

{ y = 80/8 * 15;

if(x==0){s=imagesize(0, 16, 639, 159);

buf 3 =(void *)mallco(s);

for(I = 0;i<15;i++)

{getimage(0, 16, 639, 159, buf 3);

<

p>putimage(0, 15, buf3, COPY _ PUT);

}

Gratis (buf 3); >}

outtextxy(x, y, c);

n++;

if(marca == 2 & amp; & amp(n & lt80| |x! =0))

for(I = 0;i<32767;i++)for(j = 0;j<1000;j++);

setviewport(100, 80, 540, 300, 1);

}

Calendario

/*Calendario de salida*/

# include & ltstdio. /p>

Año bisiesto (año entero)

{ if(año % 400 = = 0 | | año % 100!= 0 & amp& amp año %4==0)

Return(1);

Otros

return(0);

}

void main()

{int año;

salida nula (int);

while(1)

{printf("Ingrese el año: ") ;

scanf("%d ", & año);

Salida (año);

printf("¿Continuar? (s/n)") ; getchar(); getchar();

if(getchar()!= ' y ' & amp& ampgetchar()!= 'Y ') desconectar

}

}

Resultado no válido (entre años)

{ int a[12]={31, 28, 31, 30, 31, 30, 31, 30, 31 , 30, 31};

int i, j=0, t, p, count

suma larga = 0;

char mes[ ][12 ]={{'J','A','N'},{'F','E','B'},{'M','A','R'},{' M', 'A','Y'},{'J','U','N'},{'J','U','L'},{'A','U',' G'} ,{'S','E','P'},{'O','C','T'},{'N','O','V'},{ '

if(LEAP_YEAR(AÑO))a[1]= 29;

for(I = 0;i<Year;i++)

{if (Año bisiesto)

suma = suma+366;

Otros

suma = suma+365;

}

p =(suma+ 1)% 7;

count = p;

for(I = 0;i<12;i++)

{

printf( " \ n-\ n ");

printf("**%s** \n ", mes[I]); , jueves, viernes, sábado y domingo\ n ");

printf("-\ n ");

for(t = 0; t & lt Count; t++)

{ printf(" ");

}

for(j = 1; j & lta[I]+1; j++ )

{ printf("%3d ", j);

cuenta++;

unt = recuento % 7;

if (recuento %7==0)

printf(" \ n ");

p = recuento }

}

Regresar;

}

Conjetura de Goldbach

#Contiene "stdio.h"

#Contiene "math.h"

main()

{ int a, b, c, d

printf(" Ingrese; un número: ");

scanf("%d ", & ampa);

for(b = 3; b & lt= a/2; b+=2 )

{ for(c = 2; c & lt= sqrt(b); c++)

if(b % c = = 0)break;

if (c & gt; sqrt(b))

d = a-b;

Otro

Descanso;

for(c = 2 ;c & lt= sqrt(d);c++)

if(d % c = = 0)break;

if(c & gt;sqrt(d))

printf("%d=%d+%d\n ",a,b,d);

}

getchar();

}