Swap two number using pointer in C.
Swapping of two numbers using pointer in C programing language. | My CS Tutorial
In this post we will discuss that how to write a c program code to swap two numbers using pointer.
SWAPPING LIKE:-
FIRST NUMBER = 55
SECOND NUMBER = 30
AFTER SWAPPING
FIRST NUMBER = 30
SECOND NUMBER = 55
C PROGRAM CODE
#include<stdio.h>
#include<conio.h>
void swap(int *,int*);
void main( )
{
int a,b;
clrscr();
printf("\n ENTER THE VALUES OF A AND B:\n ");
scanf("%d%d",&a,&b);
printf ("\n VALUES OF A AND B BEFORE SWAP:\n a = %d\n b = %d\n ",a,b ) ;
swap(&a,&b ) ;
printf ("\n VALUES OF A AND B AFTER SWAP:\n a = %d\n b = %d\n ",a,b ) ;
}
void swap( int *x, int *y )
{
int t ;
t = *x ;
*x = *y ;
*y = t ;
getch();
}
OUTPUT:
Swap two numbers using pointer |
Swap two number using pointer in C.
Swapping of two numbers using
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
No comments:
Post a Comment