Hi, the question is simple but the answer isnt.) Exchange 2 integer's value except the third integer.For ex, x=10, y=20 we have to make x=20 and y=10 but we banned to use a 3. integer like integer z. I use pointers for it. #include <stdio.h> #include <stdlib.h> int main(){ int *p,*q,x=10,y=20; //first values *q=x; *p=y; x=*q; y=*p; printf("new x %d and y %d",x,y); //final values system("PAUSE"); return 0; } Code (markup): Help me solving either finding a way.
Much easier: void main() { int a,b; clrscr(); printf("\n\n\t\tenter any two nos..."); scanf("%d%d",&a,&b); a=a+b; b=a-b; a=a-b; printf("\n\n\t\tvalue of a=",a); printf("\n\n\t\tvalue of b=",b); getch(); } Code (markup):
Do not use any temp variable or pointer. Use XOR '^' operation to do that for you. y = x ^ y; x = y ^ x; y = x ^ y; regards