1输入两个整数给变量x和y;然后输出x和y;在交换x和y中的值后,在输出x和y。
1 #include <stdio.h> 2 main() 3 { 4 int x, y, t; 5 printf("enter x&y: "); 6 scanf("%d %d",&x,&y); 7 printf("x=%d y=%d ",x,y); 8 t = x; 9 x = y; 10 y = t; 11 printf("x=%d y=%d ",x,y); 12 }
2输入一个double类型的数,使该数保留小数点后两点,对第三位小数进行四舍五入处理,然后输出此数。
1 #include <stdio.h> 2 main() 3 { 4 double x; 5 printf("enter x: "); 6 scanf("%lf",&x); 7 printf("x=%f ",x); 8 x = x * 100; 9 x = x + 0.5; 10 x = (int)x; 11 x = x / 100; 12 printf("x=%f ",x); 13 }