一、N-S流程图;
二、运行结果;
三、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
int main()
{
//初始化变量值;
int world = 0;
int i = 0;
char c = 0;
char string[81] = { 0 };
int num = 0;
//提示用户;
printf("请输入一段话:");
//获取用户输入字符串;
gets(string);
//循环判断;
for (i = 0; (c = string[i]) != '\0'; i++)
{
//判断空格;
if (c == ' ')
{
world = 0;
}
else
{
//判断第几个单词;
if (world == 0)
{
world = 1;
num++;
}
}
}
//输出结果;
printf("你输入的这段话有%d个单词。\n", num);
return 0;
}