Monday, August 11, 2014

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.

// 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>

intsotu(char s[])
{
                inti=0,n=0;
                while(s[i]!='\0')
                {
                                if (s[i]==' '&&s[i+1]!=' ') n++;
                                i++;
                }
                returnn+1;
}

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

}

No comments:

Post a Comment