-
给定两个整形变量的值,将两个值的内容进行交换。
-
不允许创建临时变量,交换两个数的内容(附加题)
3.求10 个整数中最大值。
4.将三个数按从大到小输出。
5.求两个数的最大公约数。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a = 1;
int b = 2;
int t = 0;
t = a;
a = b;
b = t;
printf("%d %d\n",a,b);
system("pause");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a = 1;
int b = 2;
a = b - a;
b = b - a;
a = b + a;
printf("%d %d\n",a,b);
system("pause");
return 0;
}
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int i = 0;
int a[10];
for (i = 0; i < 10; i++)
scanf("%d", &a[i]);
int max = a[0];
for (i = 0; i < 10; i++)
if (max < a[i])
max = a[i];
printf("%d", max);
system("pause");
return 0;
}
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
int main(){
int a, b, c, t;
printf("请输入三个数");
scanf("%d %d %d", &a, &b, &c);
if (a < b)
{
t = a; a = b; b = t;
}
if (b < c)
{
t = b; b = c; c = t;
}
if (a < b)
{
t = a; a = b, b = t;
}
printf("从大到小:%d %d %d", a, b, c);
system("pause");
return 0;
}
-
define _CRT_SECURE_NO_DEPRECATE #include <stdio.h> #include<stdlib.h> #include <math.h> int gcd(int a, int b) { if (a%b == 0) return b; return gcd(b, a%b); } int main() { int a = 0, b = 0; printf("请输入a,b两个数:"); scanf("%d %d", &a, &b); printf("A=%d,B=%d\n最大公约数: \n(A,B)=%d\n", a, b, gcd(a, b)); system("pause"); return 0; }