正文

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_name3][30;
  for(i=0;i<3;i++)
      cin>>country_namei;                       //输入3个国家名
  max_string(country_name,3);                   //调用max_string函数
  return 0;
 
}
void max_string(char str[][30,int n)
{
  int i;
  char string30;
  strcpy(string,str0);                    //使string的值为str0]的值
  for(i=0;i<n;i++)
      if(strcmp(stri,string)>0)              //如果stri>string
strcpy(string,stri);               //stri]中的字符串复制到string
  cout<<endl<<the largest string is <<string<<endl;
}
运行结果如下:
CHINA
GERMANY
FRANCH
the largest string is GERMANY

阅读(946) | 评论(0)


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

评论

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