hi frinds lets learn a programme to swap two numbers withouit using temporary variable . this is in "c" Code: /*swapping of two numbers*/ #include<stdio.h> main() { int a,b; printf("enter the values of a & b"); scanf("%d %d",&a,&b); printf("the values before swapping are %d,%d",a,b); a=a+b; b=a-b; a=a-b; printf("now the values after swapping are %d,%d",a,b); }
Have you googled it You can get a lot ways of doing that on google. One of them is a = a + b; b = a - b; a = a - b;
lol was helpful. but im having trouble trying to imagine a situation where i wont be able to use a temp var. and why do u prefer scans an print to cout<< and cin
no nothing. i was just trying to imagine a situation where id love this code since i wont be able to use a Temporary Variable. but that got cleared up thanks
hey u ! i hadnt googled it i have just learnt this trick ya i agree tht there are several methods to do it i have just mentioned one of them okk
hi frinds this can also be done in differnt methods i would lyk to provide an alternate method instead of previous one as a=a*b; b=a/b; c=a/b; okk hope this will be helpful:p
no nothing. i was just trying to imagine a situation where id love this code since i wont be able to use a Temporary Variable. but that got cleared up thanks