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.
- Declaring required variables.
- Making function.
- Enters value.
- Call function.
- 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;
clrscr();
printf("Type in 2 Numbers : ");
scanf("%lf%lf", &num1,&num2);
swap(&num1,&num2);
printf("\nThe two Numbers Swapped are %lf, %lf", num1, num2);
getch();
return 0;
}
void swap (double *d1, double *d2)
{
double temp;
temp=*d1;
*d1=*d2;
*d2=temp;
}