#include stdio.h
int func(int *arr,int n)
{
int i,count=0;
for(i=0;in;i◆◆)
if(arr[i] 0)
count◆◆;
return count;
}
int main()
int a[10],i;
for(i=0;i10;i◆◆)
scanf("%d",a[i]);
printf("正整数的数量为:%d个\n",func(a,10));
return 0;
示例运行结果:
#include?stdio.h
#include?string.h
int?conNumfromStr(char?*,int);
int?main()
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◆◆)
con◆◆;
return?con;
#includelt;stdio.hgt;
void TongJi(char s[])
int ZiMu=0,KongGe=0,ShuZi=0,QiTa=0,i;
for(i=0;slt;igt;!='\0';i◆◆)
else QiTa◆◆;
printf("空格:%d;数字:%d;字母:%d;其他:%d.\n",KongGe,ShuZi,ZiMu,QiTa);
char s[100];
printf("请输入:");
gets(s);
TongJi(s);
扩展资料:
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函数的定义.
①C
int main(void)
int main(int argc,char*argv[])
当然,我们也可以做一点小小的改动.例如:char*argv[]可以写成char**argv;argv和argc可以改成别的变量名(如intval和charval),不过一定要符合变量的命名规则.
如果不需要从命令行中获取参数,请用int main(void);否则请用int main(int argc,char*argv[]).
main函数的返回值类型必须是int,这样返回值才能传递给程序的激活者(如操作系统).
#includestdio.h
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
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?==?0?string[i]!='?')
count_char[char_point]?=?string[i];
count_number[char_point]◆◆;
char_point◆◆;
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');
网页链接
以上就是土嘎嘎小编为大家整理的c语言函数统计数量相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!