progtam to swap contents of two variables using pointers

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.




#include<stdio.h>
#include<conio.h>
void swap(int *num1,int *num2);

void main()
{
int x,y;
clrscr();
gotoxy(31,1);
printf("Swap using Pointers");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);
printf("\nEnter First number : ");
scanf("%d",&x);
printf("\nEnter Second number : ");
scanf("%d",&y);
printf("\nBefore Swaping x = %d and y = %d",x,y);
swap(&x,&y);
printf("\n After Swaping x = %d and y = %d",x,y);
getch();
}

void swap(int *num1,int *num2)
{
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}

0 comments:

Post a Comment

 
Etutos © 2010-2011