请编写一个函数char *fun(char *s),其中s代表一个字符串。函数fun( )的功能是将字符串s的元素倒置。例如,输入为“teacher”,则应输出“rehcaet”。
注意:部分源程序已存在文件PROC10.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC10.cpp的内容如下:
//PROC10. cpp
#include <iostream>
#include <string>
using namespace std;
char *fun(char *s);
int main ( )
char str[81];
cout<<"Please enter a string:/n";
cin>>str;
cout<<"The result is:"<<fun(str));
cout<<end1;
return 0;
char*fun(char*s)
//* * * * * * * * *
函数fun()的定义如下:
char*fun(char *s)
{
char*head=s,*end,t;
for(end=s;*end;end++);
for(end--;s<end;s++;end--)
{
t=*s;
*s=*end;
*end=t;
}
return head;
}
编写如下事件过程:
Private sub sub1 (ByVal x1 As String, y1 As String)
Dim xt As String
Dim i As Integer
i = Len(x1)
Do While i>= 1
xt = xt + Mid(x1, i, 1)
i=i-1
Loop
y1 = xt
End Sub
Private Sub Form Click( )
Dim s1 As String, s2 As String
s1= "teacher"
sub1 s1, s2
Print s2
End Sub
程序运行后,单击窗体,则窗体上显示的内容是
A:rehcaet B:tahreee C:themee D:eerthea
编写如下事件过程: Private sub sub1 (ByVal x1 As String, y1 As String) Dim xt As String Dim i As Integer i = Len(x1) Do While i>= 1 xt = xt + Mid(x1, i, 1) i=i-1 Loop y1 = xt End Sub Private Sub Form Click( ) Dim s1 As String, s2 As String s1= "teacher" sub1 s1, s2 Print s2 End Sub 程序运行后,单击窗体,则窗体上显示的内容是
A:rehcaet B:tahreee C:themee D:eerthea
请编写一个函数char *fun(char *s),其中s代表一个字符串。函数fun( )的功能是将字符串s的元素倒置。例如,输入为“teacher”,则应输出“rehcaet”。
注意:部分源程序已存在文件PROC10.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun( )的花括号中填写若干语句。
文件PROC10.cpp的内容如下:
//PROC10. cpp
#include <iostream>
#include <string>
using namespace std;
char *fun(char *s);
int main ( )
{
char str[81];
cout<<"Please enter a string:/n";
cin>>str;
cout<<"The result is:"<<fun(str));
cout<<end1;
return 0;
}
char*fun(char*s)
{
//* * * * * * * * *
}