1
( 10分 )
编写递归函数int sum(int a[],int n),其功能是求长度为n的数组的累加和,在主函数中随机产生10个两位数,调用sum函数,求这10个数的和。
yzy's version:best version:
2
( 10分 )
编写函数get_max,其功能是将字符串s中最大字符的地址返回,再编写一个主函数,调用该函数,将字符串s中从最大字符开始的子串中小写字母转换成大写字母,然后输出新字符串s。例如,假设s的内容为“qwertyou”,则从最大字符’y’开始的子串为“you”,处理后的s为“qwertYOU”。
函数形式为:char *get_max(char s[])
yzy's version:(edited)
1 #include "iostream" 2 #define N 256 3 using namespace std; 4 char* get_max(char s[]) 5 { 6 int imax = 0; 7 for (int i = 0; s[i] != '\0'; i++) 8 { 9 if (s[i] > s[imax]) 10 imax = i; 11 } 12 return &s[imax]; 13 } 14 15 int main() 16 { 17 int n, i; 18 char* imax; 19 char a[N]; 20 gets_s(a); 21 imax = get_max(a); 22 for (i = 0; *(imax + i) != '\0'; i++) 23 { 24 if(*(imax + i) > 'a' && *(imax + i) < 'z') 25 *(imax + i) -= 32; 26 } 27 puts(a); 28 system("pause"); 29 return 0; 30 }
best version: