Swapping Numbers

View previous topic View next topic Go down

Swapping Numbers

Post by Admin on Fri Jun 26, 2015 11:18 pm

Swap two variables without using third variable.

Admin
Admin

Posts : 22
Points : 5354
Join date : 2015-06-24
Age : 23

http://csenpsb.createforum.in

Back to top Go down

Re: Swapping Numbers

Post by vinoveera on Mon Jun 29, 2015 12:53 am

#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);
}

vinoveera

Posts : 7
Points : 5304
Join date : 2015-06-27

Back to top Go down

Good answer

Post by Admin on Mon Jun 29, 2015 6:12 pm

vinoveera wrote:#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);
}

Good answer... Keep it up!!

Admin
Admin

Posts : 22
Points : 5354
Join date : 2015-06-24
Age : 23

http://csenpsb.createforum.in

Back to top Go down

Re: Swapping Numbers

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum