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...???
Answers
Answered by
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
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