自己修改一个,我给了一个简单的
void main()
{
int i = 0;
int ic = 0;
char a[100] = {"Cccomputer heccllo"};
char *p;
p = a;
while (*p != '\0')
{
if (*p>='a' && *p<='z')
{
i++;
}
if (*p>='A' && *p<='Z')
{
i++;
}
if (*p == 'c')
{
ic++;
}
p++;
}
double I = double(i);
double IC = double(ic);
double b = IC*100/I;
printf("字母一共有%d个 \n", i);
printf("c有%d个 \n", ic);
printf("c占所以字母的%%");
printf("%5.2f \n", b);
}
#include<iostream.h>
#include<string.h>
int main()
{
char a[]="computer science";
char* b=new char[10];
b=a;
int m,i;
float c=0,d=0,e=0,f=0,g=0;
m=strlen(b);
for(i=0;i<m;i++)
{
if(a[i]==97)
c++;
if(a[i]==101)
d++;
if(a[i]==105)
e++;
if(a[i]==111)
f++;
if(a[i]==117)
g++;
}
cout<<"有a"<<c<<"个,占百分之"<<100*c/m<<endl;
cout<<"有e"<<d<<"个,占百分之"<<100*d/m<<endl;
cout<<"有i"<<e<<"个,占百分之"<<100*e/m<<endl;
cout<<"有o"<<f<<"个,占百分之"<<100*f/m<<endl;
cout<<"有u"<<g<<"个,占百分之"<<100*g/m<<endl;
return 0;
}