Swap values inside the array
Swap values inside the array

How to Swap values inside the array in C

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

Thank you for reading this post, don't forget to subscribe!

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

Saurabh Nissa

This is SaurabhNissa, Owner of Thesmolt.com I'm Graduated from Magadh University in 2019 with 75%. Currently, I'm working on my Personal educational website for teaching Programming language free of Coast, and want to provide a Full setup for Specially BCA student