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

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer

FIND US ON FACEBOOK!