#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;
}
```练习代码,现在代码意识比以前强多了,但是代码的熟练度还远远不够,要勤加练习