Red de conocimiento informático - Computadora portátil - Programación de juegos de adivinanzas en lenguaje C

Programación de juegos de adivinanzas en lenguaje C

Pasó la prueba en la plataforma VC.

#include "stdio.h"

#define MAX_NUM 4

#define VERDADERO 1

#define FALSO 0

void main()

{

int i, j;

int Supongo_num[MAX_NUM] // Genera aleatoriamente cuatro números

int input[MAX_NUM]; //El usuario ingresa cuatro números

int pos_same = 0; //El número de las mismas posiciones

int num_same = 0; / Número de números idénticos

int correct = FALSE; //Juzga si la entrada es completamente correcta

//Genera aleatoriamente cuatro números entre 0 y 10

for(i = 0; ilt; MAX_NUM; i )

{

supongo_num[i] = (int)rand()10

}

for(i = 0; ilt; MAX_NUM; i )

{

printf(" d", supongo_num[i]); > }

printf("\n"); printf("Ingrese cuatro números entre 0 y 10\n");

while(!correct)

{

//Ingrese cuatro números

for(i = 0; ilt; MAX_NUM; i )

{

scanf ("d", amp; input[i]);

}

//Obtiene el número de elementos con la misma posición

for(i = 0;ilt;MAX_NUM;i )

{

if(input[i] == adivinar_num[i])

pos_same ;

}

//Obtiene el mismo número que el número aleatorio

for(i = 0; ilt; MAX_NUM; i )

{

p>

for(j = 0; jlt; MAX_NUM; j )

{

if(input[i] == adivinar_num[j])

{

num_same

descanso

}

}

if(igt; 0 ) //Juzga si es el mismo número anterior

{

for(j=i;jgt;0;j--)

{

if(input[i] ==input[j-1])

{

num_same--;

break;

}

}

}

}

printf("Número correcto de números: d\nCorrecto número de posiciones : d\n", num_same, pos_same);

num_same = (num_same ==MAX_NUM)?num_same

: 0;

pos_same = (pos_same ==MAX_NUM)?pos_same:0;

if (pos_same ==MAX_NUM amp; num_same ==MAX_NUM)

correcto = VERDADERO;

}

printf("¡Lo adivinaste!\nEl número es "); i )

{

printf(" d", supongo_num[i]

}

printf(" \n"); );

}