给定两个整形变量的值,将两个值的内容进行交换。
给定两个整形变量的值,将两个值的内容进行交换。 写法一 创建第三方变量 # define _CRT_SECURE_NO_WARNINGS 1 # include <stdio.h> # include <stdlib.h> int main ( ) { int a = 0 ; int b = 0 ; int temp = 0 ; scanf ( "%d%d" , & a , & b ) ; printf ( "a=%d b=%d\n" , a , b ) ; temp = a ; a = b ; b = temp ; printf ( "a=%d b=%d\n" , a , b ) ; system ( "pause" ) ; return 0 ; } 写法二 不创建第三方变量 # define _CRT_SECURE_NO_WARNINGS 1 # include <stdio.h> # include <stdlib.h> int main ( ) { int a = 0 ; int b = 0 ; scanf ( "%d%d" , & a , & b ) ; printf ( "a=%d b=%d\n" , a , b ) ; a = a + b ; b = a - b ; a = a - b ; printf ( "a=%d b=%d\n" , a , b ) ;