Friday, October 30, 2009

Chap8[I]b Check similar integers in array

If an array arr contains n elements, then write a program to check if arr[0] = arr[n-1], arr[1] = arr[n-2] and so on.

This program will have repeated results if the input contains more than 2 same integers



void main()
{
int arr[25];
int i,*j,k;
j=arr;

printf("\nInput 25 integers");

for(i=0;i<25;i++,j++)
{
printf("\nKey in the %d) value",i+1);
scanf("%d",&*j);
}

for(i=0;i<25;i++)
{
for(k=24;k>i;k--)
if(arr[i]==arr[k])
printf("\nArray [%d] = Array[%d]",i,k);
}
}

1 comment: