目录
1、数组形参(求平均值)
//n个学生的成绩存放在score数组中,请编写函数fun。
//它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指定的数组中
#include <iostream>
using namespace std;
int main()
{
float fix(float score[5] , int n , float new2[10]);
float sc[5] = {11,22,33,44,55} , new1[10];
int i , num ;
num = fix(sc , 5 , new1) ;
cout << "低于平均分的成绩是:";
for(i=0 ; i<num ; i++)
cout<<'\t' << new1[i] ;
}
float fix(float score[5] , int n , float new2[10])
{
float aver ;
int i , k=0 ;
for(i=0 ; i<n ; i++)
aver +=score[i];
aver /= n;
cout << "平均成绩:"<<aver<<endl ;
for(i=0 ; i<n ; i++)
if(aver > score[i]){
new2[k] = score[i];
k++;
}
return k;
}
2、指针字符串
#include <iostream>
using namespace std;
int main()
{
char *string = "I love China!";
cout << string << endl;
string = "I am a student."; //指向另一个字符串常量首地址
cout << string << endl;
return 0;
}
3、矩阵的转置
#include <iostream>
using namespace std;
int main()
{
int a[2][3] = {
{1,2,3},{4,5,6}} ;
int b[3][2] , i , j;
cout<< "矩阵a:"<<endl;
for(i=0 ; i<=1 ; i++)
{
for(j=0 ; j<=2 ; j++){
cout << a[i][j] <<'\t';
b[j][i] = a[i][j];
}
cout<<endl;
}
cout << "a的转置矩阵:"<<endl;
for(i=0 ; i<=2 ; i++){
for(j=0 ; j<=1 ; j++)
cout << b[i][j] <<'\t';
cout << endl;
}
}