64,682
社区成员
发帖
与我相关
我的任务
分享
int _tmain(int argc, _TCHAR* argv[])
{
int z;
char a[50], b[50];
system("color 49");
printf("请输入英文字符串:\n");
gets(a);
do
{
if(!(a[count]>='0'&&a[count]<='9'));
else
{
printf("输入错误\a\n请输入英文字符串:\n");
gets(a);
}
count++;
}while(a[count]>='0'&&a[count]<='9');
printf("请再次输入这窜英文字符串:\n");
gets(b);
float A=shuchu(a,b)*100;
printf("输入的正确率为:\n%f%%\n",A);
scanf("%d",&z);
return 0;
}
float shuchu(char *p,char *q)
{
int p_len = strlen(p);//在后边获取长度时候p的位置已经指向0,所以长度为0
count = 0;//在main函数也用到了count,在此置0
while(*p!='\0'&&*q!='\0')
{
if(*p==*q)
{
count++;
}
p++;
q++;
}
float d= count/p_len;
return d;
}