Monday 6 November 2017

Program to find K' th smallest number in Array In C,C++

#include<iostream>
using namespace std;

main()
{
int n,t,k;
cout<<"Enter No Of Testcases:";
cin>>t;
cout<<"Enter Number Of Elements:";
cin>>n
cout<<"Enter K'th Number To be finded:";
cin>>k;
int a[n],count=0,i,j,countb=0;
int b[n],p,q;
for(q=0;q<t;q++)
{
for(p=0;p<n;p++)
{
    cin>>a[p];
}

for(i=0;i<6;i++)
{
count=0;

int temp=a[i];
for(j=0;j<6;j++)
{
if(temp==a[j])
count++;

}
if(count==k)
{
b[i]=a[i];
countb++;
}
}
int small=b[0];
for(i=0;i<countb;i++)
{
if(small>b[i])
small=b[i];
}
cout<<"K'th Smallest Number Is:"<<small;

}

}


No comments:

Post a Comment

Amazon1Ads