2个回答
展开全部
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
FILE *f;
char x,y,a='a',A1='A',check;
int c=0,c1 = 0,c2 = 0,c3 = 0,i;
int data1[27];
int data2[27];
memset(data1,0,27*sizeof(int));
memset(data2,0,27*sizeof(int));
f = fopen("story.txt", "r");
if (f == NULL)
{
printf("Can't open the file!\n");
}
else
{
printf("是否区分大小写?Y or N\n");
scanf("%c",&y);
while (fscanf(f, "%c", &x), !feof(f))
{
if( (x>='a' && x<='z') || (x>='A' && x<='Z'))
{
c++;
if(x>='a'&&x<='z')
data1[x-'a']++;
else
{
if(y=='Y')
data2[x-'A']++;
else
data1[x-'a']++;
}
}
c1++;
}
fclose(f);
printf("字母出现的频率为:%.2lf%%\n",100.0*c/c1);
printf("请你输入要查找的字母\n");
scanf("%c",&check);
if(y=='Y')
{
if(check>='a' && check<='z')
printf("%.2lf%%\n",100.0*data1[check-'a']/c1);
else
printf("%.2lf%%\n",100.0*data2[check-'A']/c1);
}
else
{
if(check>='A' && check<='Z')
check = 'a'+check-'A';
printf("%.2lf%%\n",100.0*(data1[check-'a']+data2[check-'a'])/c1);
}
}
return 0;
}
#include <ctype.h>
#include <string.h>
int main()
{
FILE *f;
char x,y,a='a',A1='A',check;
int c=0,c1 = 0,c2 = 0,c3 = 0,i;
int data1[27];
int data2[27];
memset(data1,0,27*sizeof(int));
memset(data2,0,27*sizeof(int));
f = fopen("story.txt", "r");
if (f == NULL)
{
printf("Can't open the file!\n");
}
else
{
printf("是否区分大小写?Y or N\n");
scanf("%c",&y);
while (fscanf(f, "%c", &x), !feof(f))
{
if( (x>='a' && x<='z') || (x>='A' && x<='Z'))
{
c++;
if(x>='a'&&x<='z')
data1[x-'a']++;
else
{
if(y=='Y')
data2[x-'A']++;
else
data1[x-'a']++;
}
}
c1++;
}
fclose(f);
printf("字母出现的频率为:%.2lf%%\n",100.0*c/c1);
printf("请你输入要查找的字母\n");
scanf("%c",&check);
if(y=='Y')
{
if(check>='a' && check<='z')
printf("%.2lf%%\n",100.0*data1[check-'a']/c1);
else
printf("%.2lf%%\n",100.0*data2[check-'A']/c1);
}
else
{
if(check>='A' && check<='Z')
check = 'a'+check-'A';
printf("%.2lf%%\n",100.0*(data1[check-'a']+data2[check-'a'])/c1);
}
}
return 0;
}
展开全部
自己修改吧!大概这个模式
#include <stdio.h>
#include <ctype.h>
int main()
{
FILE *f;
char x;
int c,c1 = 0,c2 = 0,c3 = 0;
f = fopen("story.txt", "r");
if (f == NULL)
{
printf("Can't open the file!\n");
}
else
{
while (fscanf(f, "%c", &x), !feof(f))
{
if(isalpha(x))
{
c1++;
}
else
{
if(isdigit(x))
{
c2++;
}
else
{
c3++;
}
}
}
c = c1 + c2 + c3;
fclose(f);
printf("字母出现的频率为:%.2lf%%\n",100.0*c1/c);
printf("数字出现的频率为:%.2lf%%\n",100.0*c2/c);
printf("其他字符出现的频率为:%.2lf%%\n",100.0*c3/c);
}
return 0;
}
#include <stdio.h>
#include <ctype.h>
int main()
{
FILE *f;
char x;
int c,c1 = 0,c2 = 0,c3 = 0;
f = fopen("story.txt", "r");
if (f == NULL)
{
printf("Can't open the file!\n");
}
else
{
while (fscanf(f, "%c", &x), !feof(f))
{
if(isalpha(x))
{
c1++;
}
else
{
if(isdigit(x))
{
c2++;
}
else
{
c3++;
}
}
}
c = c1 + c2 + c3;
fclose(f);
printf("字母出现的频率为:%.2lf%%\n",100.0*c1/c);
printf("数字出现的频率为:%.2lf%%\n",100.0*c2/c);
printf("其他字符出现的频率为:%.2lf%%\n",100.0*c3/c);
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询