Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Have Programming Question? Ask it here!

1 Answer(s)      3 years and 7 months ago
Posted in : Design concepts & design patterns

how can i write a program to swap a value without using any arithmetic or any other third variable???

and also for adding two numbers without using any arithmetic operator??????? in c language

View Answers

January 24, 2011 at 4:00 PM

Hello Friend,

1)For swapping, use following code:

    int num1=5,num2=10;
    num1 = num1 + num2;
    num2 = num1 - num2;
    num1 = num1 - num2;

2)Add 2 Numbers:

int main()
    int num1,num2,sum;
    printf("\nEnter 1st number for addition:");
    printf("\nEnter 2nd number for addition:");
    char *p;
    p=(char *)num1;
    sum= (int)&p[num2]; //sum of num1 and num2
    printf("\nSum of %d and %d is %d",num1,num2,sum);
    return 0;

Related Tutorials/Questions & Answers: