| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 334 人关注过本帖
标题:重新又发一个
只看楼主 加入收藏
nancy_young
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-12-5
收藏
 问题点数:0 回复次数:0 
重新又发一个

我又改了一下,我就是想做个,四个数的加减乘除运算,想随机出十道题可总是做六道就出来了
#include "math.h"
#include "stdlib.h"

/* 0: +; 1:-; 2:*; 3: /; */
char cal_char_symbol[][5] =
{
"+",
"-",
"*",
"/"
};
void mydelay()
{
unsigned long i, n;

for(i = 0; i < 50000000; i++)
{
n = n+i;
}
}
int radomchar()
{
int i;
mydelay();
srand((unsigned)time(NULL));
i=rand()%4;
return i;
}

int radomnum()
{
int i,num = 0;
/*sleep(1);*/
mydelay();
srand((unsigned)time(NULL));
while(num == 0 )
num=rand()%100;
return num;
}

void leftShift(int *data, int srcPos, int shiftNum)
{
int i;
for(i = 0; i < shiftNum; i++)
{
data[srcPos + i] = data [srcPos + i +1];
}
return;
}


main()
{
int calNum[4], calSym[3];
int calNumBak[4],calSymBak[3];
int i,n,l,k,yes,no,realanswer,answer,loop;

while(1)
{

for(loop=0;loop<10;loop++)
{
for(i=0;i<4;i++)
{
calNum[i] = radomnum();
calNumBak[i] =calNum[i];

}
for(i=0;i<3;i++)
{
calSym[i] = radomchar();
calSymBak[i] = calSym[i];
}

l = 0;
for(n=0;n<2;n++)
{
for(i=0;i<3 - l ;i++)
{
if(calSym[i]<2 && (n == 0))
continue;

switch(calSym[i])
{
case 0:
realanswer = calNum[i] + calNum[i+1];
break;
case 1:
realanswer = calNum[i] - calNum[i+1];
break;
case 2:
realanswer = calNum[i]*calNum[i+1];
break;
case 3:
realanswer = calNum[i]/calNum[i+1];
break;
default:
break;
}

l++;
calNum[i] = realanswer;
leftShift(calNum, i+1, 3 -(i + 1));
leftShift(calSym, i, 2 - i);
i--;

if(l == 3)
break;

}
}

realanswer = calNum[0];

#if 1
printf("\nPlease calculate: %d%s%d%s%d%s%d = ",calNumBak[0], cal_char_symbol[calSymBak[0]],
calNumBak[1], cal_char_symbol[calSymBak[1]],
calNumBak[2], cal_char_symbol[calSymBak[2]],
calNumBak[3]);
scanf("%d",&answer);
if (realanswer==answer)
printf("congratulate");
else
printf("error");
#endif


}
printf("\nContinue,yes or no!=");
scanf("%d",&k);


if(k=yes)
printf("\nPlease calculate: %d%s%d%s%d%s%d = ",calNumBak[0], cal_char_symbol[calSymBak[0]],
calNumBak[1], cal_char_symbol[calSymBak[1]],
calNumBak[2], cal_char_symbol[calSymBak[2]],
calNumBak[3]);
scanf("%d",&answer);
if (realanswer==answer)
printf("congratulate");
else
printf("error");

getch();

getch();
}


}

2006-12-05 15:19
快速回复:重新又发一个
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015599 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved