Show program in C Write a program that asks the user to inpu
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 :)
