程序员的日常生活

想成为一个合格的程序员,每天敲代码都是必不可少的,只有在不断的实验和练习中才能走向成功,在学习中不断前进。
只有不断的迈出脚步,才能触碰到心中的远方
今日份编程:(与大家共勉)
1.给定两个整形变量的值,将两个值的内容进行交换

#define _CRT_SECURE_NO_WARNINGS
#include"stdio.h"
main()
{
	int a, b, t;
	printf("please input two numbers:\n");
    scanf("%d%d", &a, &b);
		t = a, a = b, b = t;
	printf("%d%d\n", a, b);
	return(0);
}

2.不创建临时变量,交换两个数的内容

#define _CRT_SECURE_NO_WARNINGS
#include"stdio.h"
main()
{
	int a, b;
	printf("please input two numbers:\n");
	scanf("%d%d", &a, &b);
	a = b - a;
	b = b - a;
	a = b + a;
	printf("%d%d\n", a, b);
}

3.求10个整数中的最大值

#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
main(){
	int i;
	int max = 0;
	int a[10];
	max = a[0];
	printf("please input the a[]:\n");
	for (i = 0; i < 10; i++){
		scanf("%d", &a[i]);
	
		if (max < a[i]){
			max = a[i];
		}
	}
	printf("the max is %d\n", max);

}

4.将三个数按从大到小输出

#define _CRT_SECURE_NO_WARNINGS
#include"stdio.h"

main(){
	int a, b, c, t;
	printf("please input three numbers: \n");
	scanf("%d %d %d",&a, &b, &c);
    if (a < b){
		t = a, a = b, b = t;
	}
	if (a <c ){
		t = a, a = c, c = t;
	}
	if (b < c){
		t = b, b = c, c = t;
	}
	printf("%d\t%d\t%d\n", a, b, c);

	}

5、求两个数的最大公约数

#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
int hf(int a, int b)
{
	int r, t;
	if (a < b){
		t = a;
		a = b;
		b = t;
	}
	//辗转相除法
	while ((r = a%b) != 0)
	{
		a = b;
		b = r;
	}
	return(b);
}
main(){
	int a, b, h;
	printf("please input two numbers :\n");
	scanf("%d%d", &a, &b);
	h = hf(a, b);
	printf("the result is%d\n", h);
}

总结:在编写程序中,遇到错误是避免不了的,一定要耐心对待。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值