用rand()产生随机数,rand()会产生从0到一个很大的数,我记不清了,反正很大。如果想出现100以内的,就用rand()%100。你可以定义三个int型整数,两个表示加或者减的对象,另一个标示加或者减,因为只要出现两种情况之一,所以可以用rand()%2,这样只会有0,1两种情况来标示加或者减。下面的就很容易了inta,b,i,c;for(i=0;i<10;i++){a=rand()%100;b=rand()%100;c=rand()%2;if(c==0)//标示加法{printf("%d+%d=%d\n",a,b,a+b);}else{printf("%d-%d=%d\n",a,b,a-b);}}大致就这样,希望给你点帮助
定义两个数组;
输入数字;
对这两个字符串想加;
我帮你写个字符串相加的函数 其他的你自己去完善吧;
void bigNumAdd(char * a,char * b,char* c)
{
char tempa[64] = {};
char tempb[64] = {};
char tempc[64] = {};
int j,i1,i2,i3,i4,nextadd;
int tempval1,tempval2,tempval3;
i1 = strlen(a) - 1;
for(j = 0;j<=i1;++j)
tempa[j] = a[i1 - j];
i2= strlen(b) - 1;
for(j = 0;j <= i2;++j)
tempb[j] = b[i2 - j];
i3 = (i1>i2?i1:i2);
nextadd = 0;
for(j = 0 ;j <= i3;++j )
{
if(a[j] != 0)
tempval1 = tempa[j] - '0';
else
tempval1 = 0;
if(b[j] != 0)
tempval2 = tempb[j] - '0';
else
tempval2 = 0;
tempval3 = tempval1 + tempval2;
if(nextadd>0)
{
tempval3++;
nextadd = 0;
}
if(tempval3 > 9)
{
tempc[j] = tempval3 % 10 + '0';
nextadd = 1;
}
else
tempc[j] = tempval3 + '0';
}
i4 = strlen(tempc) - 1;
for(j = 0;j <= i4;++j)
c[j] = tempc[i4 - j];
}
void main()
{
char a[64] = "5589915";
char b[64] = "494815699";
char c[64] = {};
bigNumAdd(a,b,c);
}