C++ Program to count the number of spaces in a given string [DEVCPP/GCC]


PROGRAM

//Program to count the number of spaces in a given string

#include<iostream>

using namespace std;

int main()
{
        string s;
        int len,i,count=0;

        cout<<"ENTER STRING: ";
        getline(cin,s);

        len=s.size();

        for(i=0;i<len;i++)
       {
                if(s[i]==' ')
                {
                        count++;
                }
       }

        cout<<"NUMBER OF SPACES IN THE GIVEN STRING ARE "<<count;

        return 0;
}

OUTPUT

C++ Program to count the number of spaces in a given string with output

Share this

Related Posts

FIND US ON FACEBOOK!