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.


I
Sections
2
Exercises

A

B

C

D

E

F

G

H

I

J

K

L

1

2

3

4

#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;
}

© 2020 Garbage Valuegarbage value logo