Logical Analysis and Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Swapping Numbers

2 posters

Go down

Swapping Numbers Empty Swapping Numbers

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

Swap two variables without using third variable.

Admin
Admin

Posts : 22
Points : 22749
Join date : 2015-06-24
Age : 29

https://csenpsb.board-directory.net

Back to top Go down

Swapping Numbers Empty Re: Swapping Numbers

Post by vinoveera 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 : 22699
Join date : 2015-06-27

Back to top Go down

Swapping Numbers Empty Good answer

Post by Admin 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 : 22749
Join date : 2015-06-24
Age : 29

https://csenpsb.board-directory.net

Back to top Go down

Swapping Numbers Empty Re: Swapping Numbers

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


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