/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:刘畅
* 完成日期:2014 年 12 月 1 日
* 版 本 号:v1.0
*
* 问题描述:阅读下面的程序;
* 输入描述:啥也不用输;
* 程序输出:输出该输出的。
。
(10)
#include <iostream>
using namespace std;
int f(int n);
int main()
{
cout<<f(5)<<" ";
cout<<f(8)<<endl;
return 0;
}
int f(int n)
{
static int a=2;
int b=0;
a+=n;
b+=a;
return b;
}
运行结果:
(11)
#include <iostream>
#include <cstring>
using namespace std;
void f(char p[][10],int n);
int main()
{
char p[][10]= {"China","America","Russia","England","France"};
f(p,5);
cout<<p[0]<<","<<p[4]<<endl;
return 0;
}
void f(char p[][10],int n)
{
char t[10];
int i,j;
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
if(strcmp(p[i],p[j])<0)
{
strcpy(t,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],t);
}
}
运行结果: