67 279
Assignments Done
99,1%
Successfully Done
In November 2018

Answer to Question #20179 in C++ for apoorva

Question #20179
Write a program to count number of occurrences of a given character in a string.
Expert's answer
#include <iostream>
#include <conio.h>
#include <string>

using namespace std;

void main()
{
char character;
string str;

cout << "Enter a string: ";
getline(cin, str);
cout << "Enter a character: ";
cin >> character;

int charCount = 0;
for (int c = 0; c < str.size(); c++)
if (str[c] == character)
charCount++;
cout << "There is " << charCount << " occurrences of this character in the given string." << endl;
getch();
}

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

Assignment Expert
07.08.13, 17:26

Thanks for your appreciation!
If you really liked our service please press like-button beside answer field. Thank you!

Uzair khan
22.07.13, 15:47

best program sir...

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions