Sample Qustion 9

Write a C++ program to display the smallest and greatest of given values. It also displays the value that occurs the most.    
         2,5,12,78,21,56,90,32,12,90,90,12

 #include<iostream>
using namespace std;
int main()
{
    int arr[15] = {2,5,12,78,21,56,90,32,12,90,90,12};
    int maxnum = arr[0];
    int minnum = arr[0];

  for (int i = 0; i < 12; i++)
    {
      if (arr[i] > maxnum)
        {
          maxnum = arr[i];
        }
      else if (arr[i] < minnum)
        {
          minnum = arr[i];
        }
    }
    cout <<"max number is : " << maxnum<<endl;
    cout <<"min number is : " << minnum<<endl;
    int maxRepeat=arr[0],mostrep,repeat=0;
    for (int q=0;q<12;q++)
    {
        for (int j=0;j<q;j++)
        {         //repeat=1;
                 if (arr[q] == arr[j+1])
                        repeat=repeat+1;
        }
        if (maxRepeat<repeat)
        {
            maxRepeat = repeat;
            mostrep=arr[q];
        }
    }
    cout << "the most repeated number is: " <<mostrep<< endl;
    
    return 0;
}



download file  cpp file


do you have any qustion please comment



click the advertisement to help for me ....
 




Comments

Popular posts from this blog

Java Question Data structure 04

Sample Qustion 1