by Dinesh Thakur Category: C Programming (Pratical)

In this Program user asks to Swap a two number through function. User declares the pointer type variable for interchanging the value of two variables. User asks to enter the value. User make a function named swap that will be called in other class. Then a printing message for swapped value to the function then returns a value.

In other move the function swap is been called for interchanging the values to each other. In this criteria user declare a variable temp that will use to store a temporary time value for trespassing with each other variable like mentioned in the program temp=*d1 and then to other variable. In the last instance the result is been displayed on the screen.

Problem statement:
This is Program that asks user to interchange the value with each other variable through function.

  1. Declaring required variables.
  2. Making function.
  3. Enters value.
  4. Call function.
  5. And display result on the screen.

Here is C source code for interchanging the value with each other through function Output of this program shown below. 

#include <stdio.h>
//#include <string.h>
void swap (double *d1, double *d2);          
int main ()
            double num1, num2;
            printf("Type in 2 Numbers : ");
            scanf("%lf%lf", &num1,&num2);
            printf("\nThe two Numbers Swapped are %lf, %lf", num1, num2);
            return 0;
void swap (double *d1, double *d2)
            double temp;

Swap A Two Number Through Function

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.