3942 - 3. 用gets函数输入一行字符,统计字符个数(即字符串长度)

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB
 用gets函数输入一行字符,统计字符个数(即字符串长度)

题目输入

一行字符串

题目输出

字符串长度

输入/输出样例

输入格式

hello world!

输出格式

12

C语言解答

#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
gets(str);
printf("%d\n",strlen(str));
return 0;
}

C++解答

#include<stdio.h>
int main()
{
       char a[100];
	   int i,n=0;
	   gets(a);
	   for(i=0;a[i];i++)
	      n++;
	   printf("%d",n);
	   return 0;
}