c语言问题求解 完整代码

输入一些字符,统计数字字符、字母字符及其它字符在字符串中所占的百分比。提示:请使用ctype.h头文件中定义的字符分类函数。

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>                                
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) 
{
	int a,b,c,i,n;
	char op; //字符串 
	printf("输入字节长度:");
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		op=getchar(); //输入字符串 
		if(op>='A'&&op<='Z'||op>='a'&&op<='z')
		a++;   //满足字母条件 变量+1 
		else if(op >='0'&&op<='9')
		b++;  //满足数字条件 变量+1 
		else
		c++;   
	}
	printf("字母%d  数字%d  其他%d",a,b,c);
	printf("\n");
    float A,B,C,N;
    A=a,B=b,C=c,N=n;
    printf("字母:%.1f%%  数字:%.1f%%   其他:%.1f%% ",A/N*100,B/N*100,C/N*100);
	return 0;
}

 

期待你的回复

有帮助记得采纳一下

我们也在学c 我的博文应该对你有帮助