Answer:
The program to this question can be given as:
Program:
#include<iostream> //header file
using namespace std;
int main() //main method
{
int x[10],i,largest = 0,second_largest=0,n; //variable
cout << "Enter Number of elements :"; //message
cin>>n;
cout << "Insert array elements :"; //message
for(i=0;i<n;i++) //insert elements in array
{
cin >>x[i];
}
//Finding Largest element
for(i=0;i<n;i++)
{
if (x[i]>largest)
{
largest = x[i];
}
}
//finding second largset element
for(i=0;i<n;i++)
{
if (x[i]>second_largest)
{
if(x[i]==largest)
{
continue; //Ignoring largest in order to get second largest
}
second_largest=x[i];
}
}
//print value
cout <<"Largest Number:"<<largest<<endl;
cout <<"Second Largest Number:"<<second_largest;
return 0;
}
Output:
Enter Number of elements :5
Insert array elements :33
45
75
87
23
Largest Number:87
Second Largest Number:75
Explanation:
In the above program firstly we define the header file then we define the main method in the main method we define the array and other variables. We first input the number for the size of the array. Then we insert array elements after inserting array elements we search the largest number and the second largest number in the array. To search the largest number in the array we use the loop. To search the first largest number we define a condition that array is greater than the largest number and store the value into the largest variable. Then we check the second largest number in the array for this we use two conditions that are array is greater than the second largest number in this we use another condition that is array is equal to the largest number. If the inner condition is true then it will move forward and end of an inner condition. In the outer condition, the value will be stored on the second_largest variable all the conditions will be done inner the loop. At the last we print values.
Answer:
B
Explanation:
Microsoft is an OS that updates its home about every 5-10 years
Computers are the excellent means for storage of patient related data.It is often necessary to maintain detailed records of the medical history of patients. Doctors often require the information about a patient's family history, physical ailments, already diagnosed diseases and prescribed medicines.
Answer:
// C++ program to find k largest elements in the array
#include <bits/stdc++.h>
using namespace std;
// main function
int main()
{
// variable
int n,k;
cout<<"Enter the number of elements of array:";
// read the value of n
cin>>n;
// declare the array of size n
int arr[n];
cout<<"Enter the elements of array:";
// read the elements of array
for(int a=0;a<n;a++)
{
cin>>arr[a];
}
cout<<"Enter the value of K:";
cin>>k;
// call the function to perform selection Sort
sort(arr, arr+n);
cout << k<<" largest elements of the array are: ";
// print k largest elements of the array
for (int i=n-1; i>n-k-1; i--)
cout << arr[i] << " ";
return 0;
}
Explanation:
Read the number of elements in the array.Then create an array of size "n" and read n elements of the array.Sort the array in ascending array.Then Read the value of k from user.Find the k Elements from the end of the array.This will be the k largest elements of the array.
Output:
Enter the number of elements of array:8
Enter the elements of array:34 8 75 99 12 7 5 55
Enter the value of K:3
3 largest elements of the array are: 99 75 55