#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 */
/*——————————————-
Output
How many Elements…
10
Enter Elements one by one
10
20
30
40
50
60
70
80
90
100
Resultant Array…
X[0] = 10.000000
X[1] = 20.000000
X[2] = 40.000000
X[3] = 30.000000
X[4] = 50.000000
X[5] = 60.000000
X[6] = 70.000000
X[7] = 80.000000
X[8] = 90.000000
X[9] = 100.000000
—————————————————-*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to read two integers M and N and to swap their values. Use a user-defined function for swapping. Output the values of M and N before and after swapping with suitable messages
- C program to sort given N elements using SELECTION sort method using functions a) To find maximum of elements b) To swap two elements
- C Program to accept N integer number and store them in an array AR. The odd elements in the AR are copied into OAR and other elements are copied into EAR. Display the contents of OAR and EAR
- C program to insert a particular element in a specified position in a given array
- C program to find the sum of all elements of an array using pointers as arguments
