【例3-12】将字符数组str1中所有小写字母('a'~'z')转换成大写字母
#include <iostream.h> #include <string.h> inline int up_letter(char ch); void main( ) { char str[80]; int i;
cout<<"please input a string :"; cin>>str; for(i=0;i<strlen(str);i++)
3.1 函数的定义与申明
2、函数的申明
函数声明的语法形式
类型标识符 函数名(形式参数表) {
语句序列 }
是被初始化的内部 变量,寿命和可见 性仅限于函数内部
若无返回值,写void
形式参数表 <type1> name1, <type2> name2, ..., <typen> namen
函数的返回值 由 return 语句给出;无返回值的函数(void类型), 不必写return语句
类型说明 语句
}
类型说明符 函数名(形式参数表) 形式参数类型说明
{ 类型说明 语句
}
【例3-1】 max函数的位置示例
#include <iostream.h> int max(int a,int b) {
if(a>b)return a; else return b; } void main() { int max(int a,int b); int x,y,z; cout<<"input two numbers:"<<endl); cin>>x>>y; z=max(x,y); cout<<"maxmum= "<<z<<endl; }