A company exective wants to arrange a contest and present prizes for the two top
ID: 3588009 • Letter: A
Question
A company exective wants to arrange a contest and present prizes for the two top most salesmans who sold highest number of the company goods, such as mobile phones Write a program in C++that prompts the user to enter number of contestents and number of goods sold by each salesman. The program then selects and prints the top two salesmans based on the number of goods sold. Sample input / output: ter number of contestants 7 ter number of sold items for salesnan 1: 432 ter number of sold items for salesnan 2: 150 ter number of sold items for salesnan 3 359 ter number of sold items for salesnan 4: 498 ter number of sold items for salesnan 5 19 ter number of sold items for salesnan 6: 57 ter number of sold items for salesnan 7: 617 he Topnost is 61? The Second last is 498Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
int main()
{
int k;
cout<<"Enter number of contestants :";
cin>>k;
int arr[k];
for(int i=0;i<k;i++){
cout<<"Enter number of sold items for salesman"<<i<<":"<<endl;
cin>>arr[i];
}
int n = sizeof(arr)/sizeof(arr[0]);
sort(arr, arr+n);
cout<<"The Topmost is:"<<arr[n-1]<<endl;
cout<<"The Second last is:"<<arr[n-2]<<endl;
return 0;
}
sample output:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int k;
cout<<"Enter number of contestants :";
cin>>k;
int arr[k];
for(int i=0;i<k;i++){
cout<<"Enter number of sold items for salesman"<<i<<":"<<endl;
cin>>arr[i];
}
int n = sizeof(arr)/sizeof(arr[0]);
sort(arr, arr+n);
cout<<"The Topmost is:"<<arr[n-1]<<endl;
cout<<"The Second last is:"<<arr[n-2]<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.