课本习题4
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
char a[100];
int i,daxie,xiaoxie,space,number,other;
cout<<"请输入字符长度小于100的文字:";
cin.get(a,100);
cout<<"the length of string is "<<strlen(a)<<endl;
for(i=0;i<100;i++)
{
if (a[i]>='A'&&a[i]<='Z')
daxie++;
else if(a[i]>='a'&&a[i]<='z')
xiaoxie++;
else if(a[i]>='0'&&a[i]<='9')
number++;
else if(a[i]==' ')
space++;
else if (a[i]=='\0')
other=strlen(a)-daxie-xiaoxie-number-space;
}
cout<<"其中大写字母的个数为:"<<daxie<<endl;
cout <<"其中小写字母的个数为:"<<xiaoxie<<endl;
cout<<"其中数字的个数为:"<<number<<endl;
cout<<"其他字符的个数为:"<<other<<endl;
cout<<"空格的个数为:"<<space<<endl;
return 0;
}
习题五:
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
char str[100];
cout<<"please input string:";
cin.get(str,100);
cout<<"字符串"<<str<<"的反向字符串为:\n";
for(int i =strlen(str)-1;i>=0;i--)
cout<<str[i];
cout<<"the length of string"<<str<<"is"<<strlen(str)<<endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
char a[100],b[100];
int i,j=0;
cout<<"please input string:";
cin.get(a,100);
for(i=0;i<100;i++)
{
if(a[i]>='0'&&a[i]<='9')
continue;
b[j]=a[i];
j++;
}
b[j]='\0';
cout<<"删除数字后的字符串为:"<<b<<endl;
cout<<"字符串的长度为:"<<j<<endl;
return 0;
}