Friday, 20 January 2012

In a sorted array,find element whose value is equal to its index for eg:a[2]=2,a[5]=5 etc.......


#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a[100];
printf("\nENTER THE SIZE OF THE ARRAY\n");
scanf("%d",&n);
printf("ENTER THE ELEMENTS IN THE ARRAY\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]==i)
printf("\n%d\t",a[i]);
}
getch();
}

No comments:

Post a Comment