}
return 0;
//函数实现n个数倒序输出?? void f(int b[],int x,int y) {
int *i,temp,*j,*pt; pt=b;
i=pt+x-1;j=pt+x+y-2; //i是第n个数的地址,j是第j=pt+x+y-2的地址
for(;i<=pt+(x+x+y-2)/2;i++,j--) //pt+(x+x+y-2)/2,第n个数和第n+m个数之间中
间数 }
{ } return;
temp=*i; *i=*j; *j=temp;
41
(3) 编写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其他字符的个数,在主函数中输入字符串以及输出上述结果。
#include
void count(char *str);
int letters=0,space=0,digit=0,others=0;/*这里定义了全局变量,letter表示字符,space空格,digit数字,other其他字符*/
int main(void) {
char str[100];
printf(\输入一串字符,按回车键结束:\\n\ gets(str); count(str);
printf(\字母=%d\\n空格=%d\\n数字=%d\\n其他字符=%d\\n\ return 0; }
void count(char *str)/*统计函数*/ {
while(*str!='\\0') {
if(*str>='a'&&*str<='z'||*str>='A'&&*str<='Z')/*检查字母*/ letters++;
else if(*str==' ')/*检查空格*/ space++;
else if(*str>='0'&&*str<='9')/*检查数字*/ digit++; else
others++; /*剩下的就是其他字符了*/ str++; } }
42
43
相关推荐: