हिंदी

Write a C++ program to count and print occurrence of the character ‘M’ in a given string of maximum 79 characters. - Computer Science 1

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2021-2022 (March) Set 1

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×