Problem:
Find asked greatest no in the given array without using sorting algorithm, example the array is 1,2,4,5 ,6,5,7
asked greatest no is 3 then it should print 5, if it asked 2nd greatest no then it should print 6.
Solution
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no[100],n,in,high=0;
clrscr();
printf("enter the no of no");
scanf("%d",&n);
printf("enter the no one by one");
for(i=0;i<n;i++)
scanf("%d",&no[i]);
printf("enter the which high no you need");
scanf("%d",&in);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(no[i]>no[j])
high++;
}
if(high==n-in)
{
break;
}
high=0;
}
printf("the %d big no is %d",in,no[i]);
getch();
}
Output
Find asked greatest no in the given array without using sorting algorithm, example the array is 1,2,4,5 ,6,5,7
asked greatest no is 3 then it should print 5, if it asked 2nd greatest no then it should print 6.
Solution
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no[100],n,in,high=0;
clrscr();
printf("enter the no of no");
scanf("%d",&n);
printf("enter the no one by one");
for(i=0;i<n;i++)
scanf("%d",&no[i]);
printf("enter the which high no you need");
scanf("%d",&in);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(no[i]>no[j])
high++;
}
if(high==n-in)
{
break;
}
high=0;
}
printf("the %d big no is %d",in,no[i]);
getch();
}
Output
This comment has been removed by the author.
ReplyDelete
ReplyDeletei didn't get the logic please explain