Ad

Chapter - 9: Arrays

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.


Ad
I
Sections
2
Exercises
#include<stdio.h>
#include<conio.h>
#define n 6
int main()
{
	int arr[n] = {1, 2, 3, 4, 2, 1}, i, j;

	for (i = 0, j = n - 1; i < n/2; i++, j--)
	{
		if (arr[i] == arr[j])
			printf("\narr[%d] and arr[%d] are equal.", i, j);
		else
			printf("\narr[%d] and arr[%d] are not equal.", i, j);
	}

	_getch();
	return 0;
}
Ad

© 2024 Garbage Valuegarbage value logo