作业帮 > 综合 > 作业

10以内加减法程序如何用C语言编写一个可以随机出100道10以内的加减法,并生成txt文件?呵呵,其实我并不是学语言的,

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/01 09:57:47
10以内加减法程序
如何用C语言编写一个可以随机出100道10以内的加减法,并生成txt文件?
呵呵,其实我并不是学语言的,只不过老婆在幼儿园总得出题,想给她省点事,麻烦你了!
10以内加减法程序如何用C语言编写一个可以随机出100道10以内的加减法,并生成txt文件?呵呵,其实我并不是学语言的,
// test.cpp :定义控制台应用程序的入口点.
// 在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++ 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
不过建议自己多思考,