The busy day


1,交换
#include<stdio.h>
#include<windows.h>
int main()
{
 int a=1,b=2,temp;
 temp=a;a=b;b=temp;
 printf("a=%d,b=%d\n",a,b);
 system("pause");
 return 0;
}
2.不加临时变量
#include<stdio.h>
#include<math.h>
#include<windows.h>
int main()
{
 int a,b;
 printf("input 2 number: \n");
 scanf("%d%d",&a,&b);
 a=a+b;
 b=a+b;
 a=b-a;
 b=b-2*a;
 printf("%d,%d",a,b);
 system("pause");
 return 0;
}
3.10数中最大值
#include<stdio.h>
#include<windows.h>
int main()
{
 int a[10];
 int i,j,max;
 printf("input 10 number: \n");
  for(i=0;i<10;i++)
  {scanf("%d",&a[i]);}
  max=a[0];
 for(j=1;j<10;j++)
  {if(a[j]>max)
   max=a[j];
      }
   printf("Max is: \n");
   printf("%d",max);
   printf("\n");
    system("pause");
 return 0;
}
4.三个数从大到小
#include<stdio.h>
#include<math.h>
#include<windows.h>
int main()
{
 int a,b,c,temp;
 printf("input 3 number: \n");
 scanf("%d%d%d",&a,&b,&c);
 if(a>b)
 {temp=a;a=b;b=temp;}
 if(a>c)
 {temp=a;a=c;c=temp;}
 if(b>c)
 {temp=b;b=c;c=temp;}
 printf("%d,%d,%d\n",c,b,a);
 system("pause");
 return 0;
}
5.求最大公约数
#include<stdio.h>
#include<math.h>
#include<Windows.h>
int main()   
{
 int a, b, temp;
 printf("Input two integer numbers:\n");
 scanf("%d%d", &a, &b);
  while(b!=0)
  { temp=a%b; a=b;  b=temp;}
 printf("最大公约数是:%d\n", a);
 system("pause");
}

猜你喜欢

转载自blog.csdn.net/ymk1507050118/article/details/79701465