Sunday, 14 June 2020

Swap variable value without using temporary variable

Q : Write a C program to swap the values of two variables without using the temporary variable?

Answer :

#include<stdio.h>
#include<conio.h>
/*##########################
     Girfa Student Help
     Swap two variable without
     temporary variable
  ##########################*/

void main()
{
     int a,b;
     clrscr();
     a=10;
     b=20;
     printf("A=%d\tB=%d",a,b);
     a=a+b;
     b=a-b;
     a=a-b;
     printf("\nA=%d\tB=%d",a,b);
     getch();
}

No comments:

Post a Comment