c语言编程之求输入字符串的个数
#include <stdio.h>
#include <math.h>
int main()
{
int n=0;
printf("请输入字符串:\n");
while(getchar()!='\n')
{
n++;
}
printf("输入的字符串个数为:%d",n);
return 0;
}
本文介绍了一个简单的C语言程序,该程序通过读取用户输入的字符串来计算并输出字符串的长度。利用getchar()函数逐字符读取直到遇到换行符,以此来计数。
c语言编程之求输入字符串的个数
#include <stdio.h>
#include <math.h>
int main()
{
int n=0;
printf("请输入字符串:\n");
while(getchar()!='\n')
{
n++;
}
printf("输入的字符串个数为:%d",n);
return 0;
}
1112
716

被折叠的 条评论
为什么被折叠?