不停练习自己的代码熟练度

#include <stdio.h>
#include <stdlib.h>
int main()
{
	int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	int max = arr[0];
	int sz = sizeof(arr) / sizeof(arr[0]);//确定数组元素的个数
	int i = 0;
	for (i = 1; i < sz; i++)
	{
		if (arr[i]>max)
		{
			max = arr[i];
		}
	}
	printf("max=%d\n", max);
	system("pause");
	return 0;

include <stdio.h>
#include <stdlib.h>
int main()
{
	int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	int max = arr[0];//给max赋值时不能为0,这样的话如果数组全为负数,那结果就是有问题的
	int sz = sizeof(arr) / sizeof(arr[0]);//确定数组元素的个数
	int i = 0;
	for (i = 1; i < sz; i++)//注意,这里i的取值不能是0,因为前面已经把max赋给了arr[0],i取0的话比较就没有了意义
	{
		if (arr[i]>max)
		{
			max = arr[i];
		}
	}
	printf("max=%d\n", max);
	system("pause");
	return 0;
}

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

int main()
{
	int a, b, c, t;
	printf("请输入三个数:\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 %d %d\n", a, b, c);
	system("pause");
	return 0;
	}

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

#include <stdlib.h>
#include<stdlib.h>
int main()
{
	int a = 10;
	int b = 20;
	int num = a;
	a = b;
	b = num;
	printf("a = %d\n",a );
	printf("b = %d\n",b );
	system("pause");
	return 0;
}


```练习代码,现在代码意识比以前强多了,但是代码的熟练度还远远不够,要勤加练习

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值