阅读 10,11

来源:互联网 发布:门捷列夫 知乎 编辑:程序博客网 时间:2024/06/08 11:46

运行及代码:

#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;}

在这里注意
<pre name="code" class="cpp">static int a=2;             //在全局变量前,加上关键字static,该变量就被定义成为一个静态全局变量第一次a=2,在第二次 a=7,

运行及代码:

#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);               }}
<img src="http://img.blog.csdn.net/20141207120715671?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2gyMDE0NTg1MDExMDY=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
首先对字符串进行排序,最后输出最大和最小。

0 0