5. program that inputs ten integers in an array. It displays the number of occurrences of each number in the array as follows: 3 is stored 4 times in the array. 1 is stored 1 times in the array.

Chapter 7: 

Arrays

Programming Exercise

Problem # 5:

Write a program that inputs ten integers in an array. It displays the number of occurrences of each number in the array as follows:
    3 is stored 4 times in the array.
    1 is stored 1 times in the array.

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int arr[10];
    int i, j, k, b;
    for(k=0;k<10;k++)
    {
        cout<<"Enter element "<<(k+1)<<endl;
        cin>>arr[k];
    }
    for(i=0;i<10;i++)
    {
        b=0;
        for(j=0;j<10;j++)
        {
            if(i==arr[j])
            {
                b++;
            }
        }
        cout<<i<<" number occurs "<<b<<" times."<<endl;
    }
}

Output:


Let me know in the comment section if you have any question.

Previous Post:
4. program that inputs the names and monthly salaries of 10 employees. If annual salary is greater than or equal to Rs 2,50000/- then it prints name, salary and a message "Tax to be paid" else it prints name, salary and a message "No tax".

Comments

Post a Comment