#include
#include
int main()
{
int a,b,c,d;
scanf("%d%d",&a,&b);
//借助其他变量
c=a-b;
b=b+c;
a=a-c;
printf("%d %d\n",a,b);
//不借助于其他变量;
scanf("%d%d",&c,&d);
c=c+d;
d=c-d;
c=c-d;
printf("%d %d\n",c,d);
return 0;
}
不用借助变量 int a,b; scanf("%d %d",&a,&b); b=a+b;a=b-a;b=b-a; 借助变量 int a,b,c; 同样的输入 c=a;a=b;b=c; 这是核心算法,其余的加齐就行了
C语言程序如下,谢谢采纳。
不借助临时变量
#include
void main()
{
int a=0,b=0;
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("%d\n%d",a,b);
}
借助临时变量:
#include
#include
void main()
{
int a=0,b=0,c=0;
scanf("%d%d",&a,&b);
c=a;
a=b;
a=c;
printf("%d %d\n",a,b);
system("pause");
}