用vc++编写一个程序将字符串str的字符串逆置后输出
2个回答
展开全部
#include <iostream>
using namespace std;
int main()
{
int x=0,y=0,z=0; //x统计字母;y统计数字;z统计其它
char a[50];
cout<<"请输入至多50个字符:"<<endl;
cin.get(a,50);
cout<<"=============="<<endl;
cout<<a<<endl; //输出输入的字符
cout<<"=============="<<endl;
cout<<"\n\n";
for (int i=0;i<50;i++)
{
if ((a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z'))
{x++;}
else if(a[i]>='0'&&a[i]<='9')
{y++;}
else
{z=strlen(a)-x-y;}
}
cout<<"=============="<<endl;
cout<<"字母的个数为:"<<x<<endl;
cout<<"数字的个数为:"<<y<<endl;
cout<<"其它的个数为:"<<z<<endl;
cout<<"=============="<<endl;
for (i=0;i<50;i++)
{
if(a[i]!=' ')
cout<<a[i];
if(a[i]=='\0')
break;
}
cout<<"=============="<<endl;
cout<<"倒序输出"<<endl;
for (i=strlen(a);i>=0;i--)
cout<<a[i];
cout<<"\n";
return 0;
}
using namespace std;
int main()
{
int x=0,y=0,z=0; //x统计字母;y统计数字;z统计其它
char a[50];
cout<<"请输入至多50个字符:"<<endl;
cin.get(a,50);
cout<<"=============="<<endl;
cout<<a<<endl; //输出输入的字符
cout<<"=============="<<endl;
cout<<"\n\n";
for (int i=0;i<50;i++)
{
if ((a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z'))
{x++;}
else if(a[i]>='0'&&a[i]<='9')
{y++;}
else
{z=strlen(a)-x-y;}
}
cout<<"=============="<<endl;
cout<<"字母的个数为:"<<x<<endl;
cout<<"数字的个数为:"<<y<<endl;
cout<<"其它的个数为:"<<z<<endl;
cout<<"=============="<<endl;
for (i=0;i<50;i++)
{
if(a[i]!=' ')
cout<<a[i];
if(a[i]=='\0')
break;
}
cout<<"=============="<<endl;
cout<<"倒序输出"<<endl;
for (i=strlen(a);i>=0;i--)
cout<<a[i];
cout<<"\n";
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
fun(char *s)
{int n=0,i;
char *p,t;
p=s;
while(*p!='\0'){n++;p++;}
for(i=0;i<n/2;i++){t=s[i];s[i]=s[n-1-i];s[n-1-i]=t;}
printf("%s",s );
getch();
}
main()
{char s[100];
printf("Please input your strings :\n");
gets(s);
fun(s);
}
fun(char *s)
{int n=0,i;
char *p,t;
p=s;
while(*p!='\0'){n++;p++;}
for(i=0;i<n/2;i++){t=s[i];s[i]=s[n-1-i];s[n-1-i]=t;}
printf("%s",s );
getch();
}
main()
{char s[100];
printf("Please input your strings :\n");
gets(s);
fun(s);
}
参考资料: http://zhidao.baidu.com/question/185305323.html?an=0&si=1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询