Swapping two numbers using pointers

QUESTION

Rahul and Ram played a game of exchanging their pocket money on a holiday. Rahul tries to give his pocket money to Ram and get Ram’s pocket money. \nBoth of them were strucking in to solve the problem. You help them to solve the problem.

“TESTCASE_1”: “5 4\n###—###SEPERATOR—###—\nx=5\ny=4\nAfter Swapping\nx=4\ny=5”, “TESTCASE_2”: “100 239\n###—###SEPERATOR—###—\nx=100\ny=239\nAfter Swapping\nx=239\ny=100”, “TESTCASE_3”: “18 89\n###—###SEPERATOR—###—\nx=18\ny=89\nAfter Swapping\nx=89\ny=18”, “TESTCASE_4”: “78 10\n###—###SEPERATOR—###—\nx=78\ny=10\nAfter Swapping\nx=10\ny=78”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
void swap(int *a,int *b)
{
  int temp;
  printf("x=%d\ny=%d\nAfter Swapping\n",*a,*b);
  temp=*a;
  *a=*b;
  *b=temp;
  printf("x=%d\ny=%d",*a,*b);
}
int main()
{
  int a,b;
  scanf("%d %d",&a,&b);
  swap(&a,&b);
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO