1. 给定两个整形变量的值,将两个值的内容进行交换。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a = 2, b = 9, c=0;
c = a;
a = b;
b = c;
printf(" a %d \n, b %d \n", a, b);
system("pause");
return 0;
}
2. 不允许创建临时变量,交换两个数的内容(附加题
define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a , b , c;
scanf(" %d\n %d\n", &a, &b);
c = a;
a = b;
b = c;
printf(" a %d \n, b %d \n", a, b);
system("pause");
return 0;
}
求10 个整数中最大值
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[] = { 89, 25, 1, 22, 19, 169, 57, 0, 14, 45 };
int max = a[0];
int i = 0;
for (i = 1; i < 10; i++)
{
if (max>a[i])
{
continue;
}
else{
max = a[i];
}
}
printf("%d\n", max);
system("pause");
return 0;
}
将三个数按从大到小输出。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a, b, c,d;
scanf("%d %d %d", &a, &b, &c);
if (a < b)
{
d = a;
a = b;
b = d;
}
if (a < c)
{
d = a;
a = c;
b = d;
}
if (a < c)
{
d = a;
a = c;
c = d;
}
printf("%d%d%d", a,b,c);
system(“pause”);
return 0;
}
求两个数的最大公约数
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){
int a, b, t, w;
printf("please input Two Number\n");
scanf("%d %d", &a, &b);
if (a > b)
{
t = b;
}
else
{
t = a;
}
for (int w = t; w >= 1; w--)
{
if (a%w == 0 && b%w == 0)
printf("%d \n", w);
break;
}
system("pause");
return 0;
}