﻿ Example of C Program/Code to Accept an array of 10 elements and swap 3rd element with 4th using pointers - EngineersGarage
Close or Esc Key

# Accept an array of 10 elements and swap 3rd element with 4th using pointers

`/* Write a C program to accept an array of 10 elements and swap 3rd  * *  element with 4th element using pointers. And display the results */#include <stdio.h>void main(){	float x[10];	int i,n;	void swap34(float *ptr1, float  *ptr2 ); /* Function Declaration */	printf("How many Elements...\n");	scanf("%d", &n);	printf("Enter Elements one by one\n");	for(i=0;i<n;i++)	{		scanf("%f",x+i);	}	swap34(x+2, x+3);      /* Function call:Interchanging 3rd element by 4th */	printf("\nResultant Array...\n");	for(i=0;i<n;i++)	{		printf("X[%d] = %f\n",i,x[i]);	}}     /* End of main() *//* Function to swap the 3rd element with the 4th element in the array */void swap34(float *ptr1, float *ptr2 )      /* Function Definition */{	float temp;	temp   = *ptr1;	*ptr1  = *ptr2;	*ptr2  = temp;}                                            /* End of Function *//*-------------------------------------------OutputHow many Elements...10Enter Elements one by one102030405060708090100Resultant Array...X[0] = 10.000000X[1] = 20.000000X[2] = 40.000000X[3] = 30.000000X[4] = 50.000000X[5] = 60.000000X[6] = 70.000000X[7] = 80.000000X[8] = 90.000000X[9] = 100.000000----------------------------------------------------*/`