Câu 1.13: Viết hàm đếm số từ trong một xâu ký tự chuẩn (xâu chuẩn theo nghĩa các từ trong xâu được ngăn cách bởi một dấu cách trống). Viết chương trình nhập vào từ bàn phím một xâu ký tự chuẩn s, áp dụng hàm trên thông báo ra màn hình số từ của xâu.

Monday, August 11, 2014
// bai13.cpp : Defines the entry point for the console application.
// code dung nv

#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>

int sotu(char s[])
{
                int i=0,n=0;
                while (s[i]!='\0')
                {
                                if (s[i]==' '&&s[i+1]!=' ') n++;
                                i++;
                }
                return n+1;
}

int _tmain(int argc, _TCHAR* argv[])
{
                char s[100];
                printf("Nhap vao mot xau ki tu: ");
                gets(s);
                printf("So tu trong xau vua nhap la: %d",sotu(s));
                getch();
                return 0;

}
Chia sẻ bài viết ^^
Other post

All comments [ 0 ]


Your comments