一个与数学相关的测试题
提示:
1、任意选择一个两位数(或者说,从10~99之间任意选择一个数),把这个数的十位与个位相加,再把任意选择的数减去这个和。例如:你选的数是15,然后1+5=6,然后15-6=9
2、在图表中找出与最后得出的数所相应的图形,并把这个图形牢记心中,然后点击水晶球。你会发现,水晶球所显示出来的图形就是你刚刚心里记下的那个图形。
C语言实现:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
/*
问题描述:吉普赛人祖传的神奇读心术C语言实现
*/
int randnum()//随机获取一个大写英文字母
{
int i,j;
int a[26];//用于保存26个大写英文字母的ASCLL码
for(j=65;j<91;j++)
{
a[90-j]=j;//int a[26]={65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90};
}
i=(rand()%26);
return a[i];//从数组中随机返回一个大写字母的ASCLL码
}
int main()
{
int i,letter,x,n;
printf("Direction:\n");
printf("Choose any two digit number,add together both digits and then subtract the totalfrom your original number.\n\n");
printf("When you have the final number look it up on the chart and find the relevant\nletter.Concentrate on the letter and when you have it clearly in your mind pressEnter and the programme will show you the letter you are thinking of...\n\n");
printf("*For example if you chose 56: 5+6=11. 56 minus 11 will give you your answer.\n\n");
printf("Press Any Key to start...");
getch();
restart:
system("cls");
srand((unsigned)time(NULL));
x=randnum();
for(i=0;i<99;i++)
{
if(i%11==0) printf("\n\n");
if((i+1)%9==0&&(i+1)!=90&&(i+1)!=99) printf("%3d %c |",i+1,x);
else{
letter=randnum();
printf("%3d %c |",i+1,letter);
}
}
printf("\n");
printf("Press any key to show the letter you are thinking of...");
getch();
system("cls");
printf("\n\nThe letter you are thinking of is \" %c \".",x);
printf("\n\nCan't believe it?");
loop:
printf("\n\n[1] Try again\n[2] Exit\n");
printf("[ ]\b\b");
scanf("%d",&n);
if(n!=1&&n!=2)
{
printf("Error!");
goto loop;
}
else
{
switch(n)
{
case 1:goto restart;
case 2:return 0;
}
}
}
运行结果:

