输入一个字符串,将其各个字符对应的ASCII值加5后,输出结果。
程序要求:
该字符串只包含小写字母,若其值加5后的字符值大于'z',将其转换成从a开始的字符。
#include <iostream>
using namespace std;
void str_add_fun(char *str,const int len)
{
char c;
for (int i=0;i<len;i++)
{
c=*(str+i);
c=c+5;
if (c>'z')
{
c='a'+c-'z';
}
*(str+i)=c;
}
for(int j=0;j<len;j++)
{
cout<<*(str++);
}
cout<<endl;
}
int main()
{
char a[]="abcdz";
str_add_fun(a,5);
return 0;
}