Show program in C Write a program that asks the user to inpu

Show program in C++ Write a program that asks the user to input 1 sequence of characters. Then it will ask the user for a character to search for and will output the maximum number of times that the character occurred in the sequence. Example: Sequence 1: aabccccccccc, Sequence 2: cchhcchcaaaa, If the user chooses to search for character \'a\', the program will output \"Character a occurred a maximum of 4 times\" because it occurred 4 times in the second sequence, and only twice in the first sequence.

Solution

I had made the code generic. you can add as many sequence as you want. below is the code :

#include <iostream>
#include <stdio.h>

#define size 20
using namespace std;

int main() {
  
   char ch;
   int n;
   int count;
   int maxCount=0,index=0;
   cout<<\"\ how many sequence you want to enter ? :\";
   cin>>n;
  
char sequence[n][size];

   for(int i=0;i<n;i++)
   {
   cout<<\"\ enter the sequence number \"<<i+1;
   gets(sequence[i]);
   }
  
   cout<<\"\ enter the character you want to search :\";
   cin>>ch;

   for(int i=0;i<n;i++)
   {
   count=0;
   for(int j=0;j<size;j++)
   {
   if(sequence[i][j]==ch)
   {
   count++;
   }
   }
   if(count>maxCount)
   {
   maxCount=count;
   index=i+1;
   }
   }
  
   cout<<\"\ the character \'\"<<ch<<\"\' occured a maximum of \"<<maxCount<<\"number of times in Sequence no.\"<<index;
   return 0;
}

feel free to ask if you have any doubt :)

 Show program in C++ Write a program that asks the user to input 1 sequence of characters. Then it will ask the user for a character to search for and will outp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site