-
给定两个×××变量的值,将两个值的内容进行交换。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=1;
int b=2;
int c;
c=a;
a=b;
b=c;
printf("a=%d,b=%d",a,b);
system("pause");
return 0;
}- 不允许创建临时变量,交换两个数的内容(附加题)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=2, b=3;
a=a+b;
b=a-b;
a=a-b;
printf("a=%db=%d",a,b);
getcher ();
system("pause");
return 0;
}3.求10 个整数中最大值。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[] = {5,9,2,7,8,6,4,3,12,16};
int i , max=[0];
for (i=0;i<10;i++)
{
if (max < a[i])
max = a[i];
}
printf("max=%d\n",max);
system("pause");
}4.将三个数按从大到小输出。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c,temp;
scanf("%d %d %d",&a,&b,&c);
if(b<a)
{
temp = a;
a = b;
b = temp;
}
if(c<b)
{
temp = b;
b = c;
c = temp;
}
if(b<a)
{
temp = a;
a = b;
b = temp;
}
printf("%d%d%d\n",c,b,a);
system("pause")
return 0;
}5.求两个数的最大公约数。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,t;
scanf("%d %d", &a, &b);
while(b != 0)
{
t = a % b;
a = b;
b = t;
}
printf("最大公约数=%d\n",a);
system("pause");
return 0;
}
转载于:https://blog.51cto.com/13102482/2362666