1.将两个整形变量的值得内容进行交换
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int a = 2;
int b = 4;
a = a + b;
b = a - b;
a = a - b;
printf(“a=%d,b=%d”, a, b);
system(“pause”);
return 0;
}
2.求10个整数中的最大值
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int a[] = { 2, 1, 5, 3, 6, 9, 11, 8, 12, 10 };
int i;
int max = a[0];
for (i = 0; i < 10; i++)
{
if (max < a[i])
max = a[i];
}
printf(“max number is %d\n”, max);
system(“pause”);
return 0;
}
3.将三个数按从大到小输出
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int a, b, c, m;
scanf("%d%d%d", &a, &b, &c);
if (a < b)
{
m = a;
a = b;
b = m;
}
if (a < c)
{
m = a;
a = c;
c = m;
}
if (b < c)
{
m = b;
b = c;
c = m;
}
printf("%d%d%d", a, b, c);
system(“pause”);
return 0;
}
4.求两个数的最大公约数
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int a, b;
printf(“请输入两个数(a,b):”);
scanf("%d%d", &a,&b);
while (a!=b)
{
if (a > b)
a = a - b;
else
b = b - a;
}
printf("最大公约数为:%d\n",a);
system("pause");
return 0;
}