Swap values inside the array

Dear Student here you learn how to swap value inside Array using For loop, Here we only provide a demo for your Understanding, we don’t suggest you that do copy & Paste so please, If you want to do something better in your life, Always try to run your code on Compiler honestly until you don’t understand actually how works it. Thank You

Swapping value Inside The Array in C

#include<stdio.h>
void swap (int *x,int i, int n)
{
int temp = *(x+i);
*(x+i) = *(x+(n-1));
*(x+(n-1)) = temp;


}
void main()
{
int a[10],i,j,k,n=10;
for(i=0;i<n;i++)
a[i]=i+1;

for(j=0;j<n/2;j++)
{
swap (a,j,n-j);
}

for(i=0;i<n;i++)
printf("%d\n",a[i]);

}

C Program for Swapping value in Array

Learn more C program (click)

10

9

8

7

6

5

4

3

2

1

Swappin Value in Array

Swap values inside the array

Swapping Array In C

 

Thank You

Leave a Reply

x