Yasir's Blog
Pages
About Me
C Programs
Java Programs
ML
Contact Me
Sitemap
Privacy Policy
Home
»
C Programs
»
C Program to Swap Two Numbers
Monday, 2 January 2017
C Program to Swap Two Numbers
Program:
This program is saved as Swap.c
#include
int main() { int x,y,temp; printf("Enter the value of x and y\n"); scanf("%d%d",&x,&y); printf("Before Swapping\nx=%d\ny=%d\n",x,y); temp = x; x = y; y = temp; /* using temp to swap storing x to temp and y to x then moving temp to y */ printf("After Swapping\nx=%d\ny=%d\n",x,y); return 0; }
Output:
Enter the value of x and y 86 134 Before Swapping x=86 y=134 After Swapping x=134 y=86
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment