![]() |
Program to count the number of words and characters in a sentence 1 Attachment(s) Program to count the number of words and characters in a sentence #include #include void main() { clrscr(); int countch=0; int countwd=1; cout << "Enter your sentence in lowercase: " << endl; char ch='a'; while(ch!='\r') { ch=getche(); if(ch==' ') countwd++; else countch++; } cout << "\n Words = " << countwd << endl; cout << "Characters = " << countch-1 << endl; getch(); } It then determines the number of words and characters in the sentence using the 'WHILE' loop and outputs them using the 'cout' command. Sample Input this is a nice program Sample Output Words = 5 Characters = 18 |
| All times are GMT +5. The time now is 04:13 PM. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.