第二次课程作业
給定兩個×××變量的值,將兩個值的內(nèi)容進(jìn)行交換。
#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 個整數(shù)中最大值。
#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.將三個數(shù)按從大到小輸出。
#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.求兩個數(shù)的最大公約數(shù)。
#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("最大公約數(shù)=%d\n",a);
system("pause");
return 0;
}
轉(zhuǎn)載于:https://blog.51cto.com/13102482/2362666
總結(jié)
- 上一篇: 数组随机排列
- 下一篇: 2、RabbitMQ-simplest