编写函数int fun(char *str),功能是:统计字符串str中不同字符的个数并做为函数值返回。例如,下面程序运行时若输入:One world,One dream! 输出:n=13

it2023-02-17  91

#include<stdio.h> int fun(char *str) { int i,j,n=0; for(i=0;str[i];i++){ for(j=0;j<i;j++){ if(str[i]==str[j]) break; } if(i==j) n++; } return n; } int main() {char s[80]; int n; gets(s); n=fun(s); printf("n=%d\n",n); }
最新回复(0)