Computer Science, asked by joney, 1 year ago

write a program which interchanges the values the variable using only assignments operations.what is the minimum no of assignments operations required.


joney: what is the progress on my question...???
lfstone3: java c++ or php which one of them?
joney: in c language
joney: is anybody there...???
joney: hello... help me plzzz

Answers

Answered by kvnmurty
1
#include <stdio.h>
main ()
{
      int  a, b ;
     
            printf("Input a: "); scanf("%d", &a);
            printf("Input b: "); scanf("%d", &b);
            a = (a+b) ;
            printf ("values a: %d , %d\n", a, b);
            b = (a-b) ;   // now b = original value of a
            printf ("values a: %d , %d\n", a, b);
            a = (a - b ) ; // now a = original value of b
            printf ("values a: %d , %d\n", a, b);
}

minimum number of assignments needed = 3


Similar questions