1.
5 athletes took part in the 10-meter platform diving competition, someone let them predict match results,
player A says: B second, my third;
B players said: I second, E IV;
C contestant said: I first , D second;
D players, said: C Finally, my third;
E contestant said: I IV, a first;
after the game, each player say half right, please programmed to determine the ranking of the game.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a, b, c, d, e;
for (a = 1; a <= 5; ++a)
{
for (b = 1; b <= 5; ++b)
{
for (c = 1; c <= 5; ++c)
{
for (d = 1; d <= 5; ++d)
{
for (e = 1; e <= 5; ++e)
{
if (a*b*c*d*e == 120)
{
if(((b == 2) + ( a == 3) == 1) &&
((b == 2) + (e == 4)== 1) &&
((c == 1) + (d == 2) == 1) &&
((c == 5) + (d == 3) == 1) &&
((e == 4) + (a == 1) == 1))
{
printf("a = %d, b = %d, c = %d, d = %d, e = %d", a, b, c, d, e);
}
}
}
}
}
}
}
printf("\n");
system("pause");
return 0;
}
2.
Japan somewhere there have been a murder, the police through the investigation to determine the murderer will be for 4
a suspects. The following is the four suspects confession.
A said: not me.
B said: It is C.
C said: It is D.
D said: C nonsense
known three people told the truth, one person was lying.
Based on this information now, please, write a program to determine in the end who is the murderer.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int killer = 0;
for (killer = 'A'; killer <= 'D'; ++killer)
{
if ((killer != 'A') + (killer == 'C') + (killer == 'D') + (killer != 'D') == 3)
{
printf("killer is %c\n", killer);
}
}
system("pause");
return 0;
}
3. Pascal's Triangle print on the screen.
. 1
. 1. 1
. 1 2. 1
. 1. 1. 3. 3
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define N 10
int main()
{
int array[N][N] = { 0 };
int i = 0;
int j = 0;
int k = 0;
for (i = 0; i < N; i++)
{
array[i][1] = 1;
array[i][j] = 1;
}
for (i = 2; i < N; ++i)
{
for (j = 1; j < 10; ++j)
{
array[i][j] = array[i - 1][j] + array[i - 1][j - 1];
}
}
for (i = 0; i < N; ++i)
{
for (j = 0; j <= i; ++j)
{
printf("%d ", array[i][j]);
}
for (k = 0; k < N - i; ++k)
{
printf(" ");
}
printf("\n");
}
system("pause");
return 0;
}