c语言统计数字个数函数 c语言统计数字字符个数程序

C语言:用函数统计一串数字中相同数字的个数#define MAX_NUMBER 80
#includestdio.h
int main()
{
char string[MAX_NUMBER],count_char[MAX_NUMBER];
int count_number[MAX_NUMBER],i,j,char_point=0,temp;
// init
for(i=0;iMAX_NUMBER;i++)
{
count_char[i] = ' ';
string[i] = ' ';
count_number[i] = 0;
}
i = 0;
do
{
scanf("%c",string[i]);
temp = string[i];
i++;
}while(temp != '\n');
//printf("%s",string);
// count
for(i=0;iMAX_NUMBER;i++)
{
temp=0;
for(j=0;jMAX_NUMBER;j++)
{
if(string[i]!=' ')
{
//printf("0: %c 1: %c \n",string[i],count_char[j]);
if(string[i] ==count_char[j])
{
count_number[j]++;
temp=1;
}
}
}
if(temp == 0string[i]!=' ')
{
count_char[char_point] = string[i];
count_number[char_point]++;
char_point++;
}
}
temp=0;
do
{
if(temp == 0)
printf("%c:%d",count_char[temp],count_number[temp]);
else
printf(",%c:%d",count_char[temp],count_number[temp]);
temp++;
}while(count_char[temp]!='\n');
return 0;
}
网页链接
c语言 , 编一个函数,统计任意一串字符中数字字符的个数,并在主函数中调用此函数 。#include stdio.h
#include string.h
int conNumfromStr(char *,int);
int main()
{
char str[21];
printf("输入20以内的字符:");
scanf("%s",str);
printf("字符串中数字字符个数为:%d",conNumfromStr(str,strlen(str)) );
return 0;
}
int conNumfromStr(char *p,int len)//计数字符串中数字字符的个数
{
int i,con=0;
for(i=0;ilen;i++)
{
if(p[i]='0'p[i]='9')
con++;
}
return con;
}
C语言编程:编写函数 , 统计字符串中字母、数字、空格和其他字符的个数 。#includelt;stdio.hgt;
void TongJi(char s[])
{
int ZiMu=0,KongGe=0,ShuZi=0,QiTa=0,i;
for(i=0;slt;igt;!='\0';i++)
{
if(slt;igt;==32)KongGe++;
else if((slt;igt;gt;=48)(slt;igt;lt;=57))ShuZi++;
else if(((slt;igt;gt;=97)(slt;igt;lt;=122))||((slt;igt;gt;=65)(slt;igt;lt;=90)))ZiMu++;
else QiTa++;
}
printf("空格:%d;数字:%d;字母:%d;其他:%d 。\n",KongGe,ShuZi,ZiMu,QiTa);
}
int main()
{
char s[100];
printf("请输入:");
gets(s);
【c语言统计数字个数函数 c语言统计数字字符个数程序】TongJi(s);
return 0;
}
扩展资料:
return用法
C++的关键字,它提供了终止函数执行的一种方式 。当return语句提供了一个值时,这个值就成为函数的返回值.
说到return,有必要提及主函数的定义,下面是从网络上找到的资料,好好消化吧,对了解主函数中返回值的理解有很大的帮助.
很多人甚至市面上的一些书籍,都使用了void main(),其实这是错误的 。C/C++中从来没有定义过void main() 。
C++之父Bjarne Stroustrup在他的主页上的FAQ中明确地写着The definition void main(){/*...*/}is not and never has been C++,
nor has it even been C.(void main()从来就不存在于C++或者C) 。下面我分别说一下C和C++标准中对main函数的定义 。
1.C
在C89中,main()是可以接受的 。Brian W.Kernighan和Dennis M.Ritchie的经典巨著The C programming Language 2e(《C程序设计语言第二版》)用的就是main() 。不过在最新的C99标准中,只有以下两种定义方式是正确的:
int main(void)
int main(int argc,char*argv[])
(参考资料:ISO/IEC 9899:1999(E)Programming languages—C 5.1.2.2.1 Program startup)
当然 , 我们也可以做一点小小的改动 。例如:char*argv[]可以写成char**argv;argv和argc可以改成别的变量名(如intval和charval),不过一定要符合变量的命名规则 。

推荐阅读