新增 指针/求最大值 .cpp
This commit is contained in:
19
指针/求最大值 .cpp
Normal file
19
指针/求最大值 .cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
1 #include<iostream>
|
||||||
|
2 using namespace std;
|
||||||
|
3
|
||||||
|
4 int main(){
|
||||||
|
5 int max,*ptr;
|
||||||
|
6 int arr[5]={10,20,33,15,11};
|
||||||
|
7 max = arr[0];
|
||||||
|
8 ptr = arr;
|
||||||
|
9
|
||||||
|
10 for (int i = 0; i < 5; i++) {
|
||||||
|
11 if (*ptr > max) {
|
||||||
|
12 max = *ptr;
|
||||||
|
13 }
|
||||||
|
14 ptr++;
|
||||||
|
15 }
|
||||||
|
16 cout << "最大值是:"<< max<<endl;
|
||||||
|
17
|
||||||
|
18 return 0;
|
||||||
|
19 }
|
||||||
Reference in New Issue
Block a user