Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a program that asks the user to input a sentence and prints the number of letters and words in the sentence?

0 votes
asked Oct 31, 2017 by Amira Ibrahim (120 points)

4 Answers

0 votes
answered Nov 5, 2017 by Ruturaj Khandare
#include <stdio.h>

int main()
    int i=0,countl=0,countw=0;
    char my1[200],a;
    printf("enter sentence ");
        if(my1[i]==' ')
         printf("%c ",my1[i]);
       printf("\n no of letter = %d",countl);
    printf("\n no of words = %d",countw);

    return 0;
commented Nov 24, 2017 by anonymous
There is a bug in this program, what if two contiguous spaces are there?
0 votes
answered Nov 28, 2017 by fathamd (180 points)
import java.util.Scanner;

public class demo {

    public static void main(String[] args) {

    Scanner input =new Scanner(System.in);
    int sum=0, len=0;
    System.out.println("please input the sequence");
    String str= input.nextLine();
    String[] st=str.split(" ");
    for(int i= 0;i<st.length;i++) {
    System.out.println("number of chars are:" + sum);
    System.out.println("number of words are:" + len);

0 votes
answered May 23, 2020 by dinesh sen (290 points)
s=str(input('write a sentence : '))
for x in range(0,n):
    if (s[x])==" ":
print('total words are : {0}'.format(sp+1))
print('total letters are : {0}'.format(n-sp))
0 votes
answered May 24, 2020 by Jha Mrityunjay (140 points)
using namespace std;
int main()
    string s;
    int i,x=0,y=0;
    int n=s.length();
    for(int i=0;i<n;i++)
        if(s[i]!='/0') x++;
        if(s[i]==' ') y++;
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.