// 在vc2008下调试通过
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
int main()
{
FILE * myfile
myfile = fopen("e:\\test.txt","w")
char result[50]
char op
int i = 0
while( i++<100)
{
int a = rand() % 10
int b = rand() % 19// 生成 0 - 18 b为 0 - 9做加法 10 - 18 做减法
b = 9 - b
int r = a + b
if( b >0)
op = '+'
else
op = '-'
b = abs(b)
sprintf(result,"%d %c %d = %d\n",a,op,b,r)
fputs(result,myfile)
}
fclose(myfile)
return 0
}
部分结果如下
1 - 9 = -8
4 - 5 = -1
9 - 2 = 7
8 + 6 = 14
2 - 2 = 0
5 + 3 = 8
1 - 3 = -2
1 - 7 = -6
5 - 1 = 4
7 + 7 = 14
1 - 3 = -2
2 + 8 = 10
2 - 4 = -2
不过建议自己多思考,祝你成功
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)