Q6 Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

Swapping of two numbers with or without using third variable

Program: 56

Write a c program to swap two numbers without using third variables | Let Us C Solutions

#include<stdio.h>
int main()
{
    int C, D, T;
     printf("Enter the value of C: ");
     scanf("%d", &C);

     printf("Enter the value of D: ");
     scanf("%d", &D);

     C = C+D; //c=30, d=20
     D = C-D; //d=10, c=30
     C = C-D; //c=20


     printf("\n The value of C: %d", C);
     printf("\n The value of D: %d", D);
     getch();
}

Output:

Enter the value of C: 10
Enter the value of D: 20
 
 The value of C: 20
 The value of D: 10

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.