初学c语言

  1. 给定两个整形变量的值,将两个值的内容进行交换。

  2. 不允许创建临时变量,交换两个数的内容(附加题)
    3.求10 个整数中最大值。
    4.将三个数按从大到小输出。
    5.求两个数的最大公约数。

#include<stdio.h>
#include<stdlib.h>

int main()
{
int a = 1;
int b = 2;
int t = 0;
t = a;
a = b;
b = t;
printf("%d %d\n",a,b);
system("pause");

return 0;
}
#include<stdio.h>
#include<stdlib.h>

int main()
{
int a = 1;
int b = 2;
a = b - a;
b = b - a;
a = b + a;
printf("%d %d\n",a,b);
system("pause");

return 0;
}
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
   int i = 0;
int a[10];
for (i = 0; i < 10; i++)
	scanf("%d", &a[i]);
int max = a[0];
for (i = 0; i < 10; i++)
	if (max < a[i])
	
	max = a[i];
	printf("%d", max);
	system("pause");


return 0;
}
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
int main(){

int a, b, c, t;
printf("请输入三个数");
scanf("%d %d %d", &a, &b, &c);
if (a < b)
{
	t = a; a = b; b = t;
}
if (b < c)
{
	t = b; b = c; c = t;
}
if (a < b)
{
	t = a; a = b, b = t;

}
printf("从大到小:%d %d %d", a, b, c);
system("pause");

return 0;
}
  1.  define _CRT_SECURE_NO_DEPRECATE
     #include <stdio.h>
     #include<stdlib.h>
     #include <math.h>
     int gcd(int a, int b)
     {
     if (a%b == 0)
     return b;
     return gcd(b, a%b);
     }
     int main()
     {
     int a = 0, b = 0;
     printf("请输入a,b两个数:");
     scanf("%d %d", &a, &b);
     printf("A=%d,B=%d\n最大公约数: \n(A,B)=%d\n", a, b, gcd(a, b));
     system("pause");
     return 0;
     }
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值