Question-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.
Solution-
an easy problem.but I am not sure that till how many elements ,we are supposed to check in. I made a program for just 10 elements .let's see the solution...
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[10],i;
printf("Enter the elements of the array\n");
for(i=0;i<=9;i++)
scanf("%d",&arr[i]);
check(arr);
getch();
}
check(int *arr[10])
{
int i,j=9;
printf("Following array elements are equal\n");
for(i=0;i<=5;i++)
{
if(arr[i]==arr[j]) /*Equating the array elements */
printf("array[%d]=array[%d]\n",i,j);
j--;
}
}
check if arr[0] = arr[n-1], arr[1] = arr[n-2]and so on.
Solution-
an easy problem.but I am not sure that till how many elements ,we are supposed to check in. I made a program for just 10 elements .let's see the solution...
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[10],i;
printf("Enter the elements of the array\n");
for(i=0;i<=9;i++)
scanf("%d",&arr[i]);
check(arr);
getch();
}
check(int *arr[10])
{
int i,j=9;
printf("Following array elements are equal\n");
for(i=0;i<=5;i++)
{
if(arr[i]==arr[j]) /*Equating the array elements */
printf("array[%d]=array[%d]\n",i,j);
j--;
}
}
No comments:
Post a Comment