#include
#include
#include
int main()
{
int n,i,j,t;
srand(time(NULL));
for(n=0;n<10;n++)
{
i=rand()%100+1;
j=rand()%100+1;
if(i printf("%d-%d=\n",i,j); } getch(); return 0; }
先生成被减数,再由被减数生成减数。
int num1=rand()%100+1;
while(num1==1)
num1=rand()%100+1;
int num2=rand()%(num1-1)+1;
printf("%d-%d=%d\n",num1,num2,num1-num2);
#include
#include
#include
int main(){
int i,a,b;
srand(time(0));
for(i=0;i<10;i++){
a=rand()%100+1;
b=rand()%100+1;
while(b==a) b=rand()%100+1; //减数和被减数不相同
if(a a^=b;
b^=a;
a^=b;
}
printf("%3d -%3d=%3d\n",a,b,a-b);
}
return 0;
}