64 613
Assignments Done
99,1%
Successfully Done
In September 2018

Answer to Question #20172 in C++ for apoorva

Question #20172
Write a program to count the number of words in a string as well as the number of characters other than a space.
Expert's answer
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <iostream.h>
int main(void)
{
char s[255];
cout<<"Enter the string: ";
gets(s);
unsigned int a,i;
a=0;
for (i=0;i<strlen(s)-1;i++)
& if ((s[i]==' ') && (s[i+1]!=' '))
& a=a+1;
if (s[0]!=' ')
a=a+1;
cout<<"number of words: "<<a<<endl;
a=0;
for (i=0;i<strlen(s)-1;i++){
if (s[i+1]!=' ')
& a=a+1;
}



cout<<"The number of characters other than a space : "<<a<<endl;



system ("PAUSE");

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions