Advertisements
Advertisements
Question
Write a C++ program to count and print occurrence of the character ‘M’ in a given string of maximum 79 characters.
Code Writing
Advertisements
Solution
#include <iostream.h>
#include <conio.h>
void main()
{
char str[80];
int i, count = 0;
cout << "Enter a string: ";
cin.getline(str, 80);
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] == 'M')
count++;
}
cout << "Number of occurrences of 'M' = " << count;
getch();
}shaalaa.com
Is there an error in this question or solution?
