int arr[5]={300,350,200,400,250};int max = arr[0];for(int i =0; i <5; i++){if(max<arr[i]){
max = arr[i];}}
cout << max << endl;
1.3 元素逆置
int arr[]={1,3,2,5,4,6};int num =sizeof(arr)/sizeof(arr[0]);for(int i =0; i <sizeof(arr)/sizeof(arr[0])/2; i++){int flag=0;
flag = arr[i];
arr[i]= arr[sizeof(arr)/sizeof(arr[0])-1- i];
arr[sizeof(arr)/sizeof(arr[0])-1- i]= flag;}for(int j =0; j <sizeof(arr)/sizeof(arr[0]); j++){
cout << arr[j]<< endl;}
1.4 冒泡升序
int arr[]={4,2,8,0,5,7,1,3,9};int num =sizeof(arr)/sizeof(arr[0]);for(int i =0; i <sizeof(arr)/sizeof(arr[0]); i++){for(int j =0; j <sizeof(arr)/sizeof(arr[0])-i-1; j++){if(arr[j]>arr[j +1]){int flag =0;
flag = arr[j];
arr[j]= arr[j +1];
arr[j +1]= flag;}}}for(int k =0; k <sizeof(arr)/sizeof(arr[0]); k++){
cout << arr[k];}
二维数组,三人总分
int score[3][3]={{100,100,100},{90,50,100},{60,70,80}};int sum[3]={0,0,0};for(int i =0; i <3; i++){int sum =0;for(int j =0; j <3; j++){
sum[i]= score[i][j]+sum[i];
sum += score[i][j];}
cout << sum[i]<< endl;
cout << sum << endl;}
2 函数
函数建立
#include<iostream>usingnamespace std;#include"max.h"intadd(int num1,int num2){int sum = num1 + num2;return sum;}/**********************************/voidswap(int num1,int num2){int flag = num1;
num1 =num2;
num2 = flag;}intmain(){/*int a = 10;
int b = 20;
int c=add(a, b);
cout << c << endl;*/int a =10;int b =20;swap(a, b);//这样是不会改变值的
cout << a << endl;
cout << b << endl;system("pause");return0;}