Deleting the Duplicates from an array
#include<stdio.h>
#include<conio.h>
void main()
{
int n, a[10], b[10], count = 0, i, j;
clrscr();
printf("Enter the Range :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter a[%d]",i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<count;j++)
{
if(a[i]==b[j])
break;
}
if(j==count)
{
b[count] = a[i];
count++;
}
}
printf("Array obtained after removing duplicate elements\n");
for(i=0;i<count;i++)
printf("%d\n",b[i]);
getch();
}
#include<conio.h>
void main()
{
int n, a[10], b[10], count = 0, i, j;
clrscr();
printf("Enter the Range :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter a[%d]",i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<count;j++)
{
if(a[i]==b[j])
break;
}
if(j==count)
{
b[count] = a[i];
count++;
}
}
printf("Array obtained after removing duplicate elements\n");
for(i=0;i<count;i++)
printf("%d\n",b[i]);
getch();
}
Finding the Kth largest Element in an array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20];
int num,k,i,c;
clrscr();
printf("Enter number of elements\n");
scanf("%d",&num);
printf("Enter elements\n");
for(i=0;i<num;i++)
{
printf("Enter a[%d] = ",i);
scanf("%d",&a[i]);
}
printf("Enter k\n");
scanf("%d",&k);
c=1;
for(i=1;i<num;i++)
{
if(c==k)
{
printf("kth Smallest with k=%d is %d",k,a[i-1]);
break;
}
if(a[i]!=a[i-1])
c++;
}
getch();
}
#include<conio.h>
void main()
{
int a[20];
int num,k,i,c;
clrscr();
printf("Enter number of elements\n");
scanf("%d",&num);
printf("Enter elements\n");
for(i=0;i<num;i++)
{
printf("Enter a[%d] = ",i);
scanf("%d",&a[i]);
}
printf("Enter k\n");
scanf("%d",&k);
c=1;
for(i=1;i<num;i++)
{
if(c==k)
{
printf("kth Smallest with k=%d is %d",k,a[i-1]);
break;
}
if(a[i]!=a[i-1])
c++;
}
getch();
}
No comments:
Post a Comment