Advertisements
Advertisements
प्रश्न
Write a C++ program to count and print occurrence of the character ‘M’ in a given string of maximum 79 characters.
कोड लेखन
Advertisements
उत्तर
#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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
