Interview Questions   Tutorials   Discussions   Programs   

C - Write a program to swap Two numbers without using temp variable?




268
views
asked marvit August 18, 2014 06:14 AM  

Write a program to swap Two numbers without using temp variable?


           

1 Answers



 
answered By bhjahnavi   0  
/* program to swap two number without using temparary variable*/
#include<stdio.h>
 
int main() {
  int a, b;
 
  printf("\nEnter value for num1 & num2 : ");
  scanf("%d %d", &a, &b);
 
  a = a + b;
  b = a - b;
  a = a - b;
 
  printf("\nAfter swapping value of a : %d", a);
  printf("\nAfter swapping value of b : %d", b);
 
  return (0);
}


output:
Enter value for num1 & num2 : 10 20
 
After swapping value of a : 20
After swapping value of b : 10
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert