正文

C++ 入门第5章5.5.5.6 字符数组应用举例2008-09-27 13:17:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/yzrj/38529.html

分享到:

  例5.10 有3个字符串,要求找出其中最大者。要求用函数调用。 程序如下: #include <iostream> #include <string> using namespace std; int main( ) { void max_string(char str[][30],int i);        //函数声明 int i;   char country_name[3][30];   for(i=0;i<3;i++)       cin>>country_name[i];                       //输入3个国家名   max_string(country_name,3);                   //调用max_string函数   return 0;   } void max_string(char str[][30],int n) {   int i;   char string[30];   strcpy(string,str[0]);                    //使string的值为str[0]的值   for(i=0;i<n;i++)       if(strcmp(str[i],string)>0)              //如果str[i]>string strcpy(string,str[i]);               //将str[i]中的字符串复制到string   cout<<endl<<″the largest string is: ″<<string<<endl; } 运行结果如下: CHINA↙ GERMANY↙ FRANCH↙ the largest string is: GERMANY

阅读(960) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册