Skip to main content

Posts

Showing posts with the label c program to swap two numbers using functions call by value

Sample C Program To Swap Two Numbers Using & Without Temporary Variables.

#include <stdio.h> #include <conio.h> main() {     int x, y, temp;     printf("Enter the value of x and y ");     scanf("%d %d", & x, & y);     printf("Before Swapping\nx = %d\ny = %d\n",x,y);     temp = x;     x = y;     y = temp;     printf("After Swapping\nx = %d\ny = %d\n",x,y);     getch();     return 0; } OUTPUT: Enter the value of x and y 2 4 Before Swapping x = 2 y = 4 After Swapping x = 4 y = 2 C Program To Swap Two Numbers Without Using Temp Variable. #include <stdio.h> main() {     int a, b;     printf("Enter two numbers to swap ");     scanf("%d %d", & a, & b);     a = a + b;     b = a - b;     a = a - b;     printf("a = %d\nb = %d\n",a,b);     return 0; } OUTPUT: Enter two numbers to swap 2 4 a = 4 b = 2 C ...