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




Have Programming Question? Ask it here!
 
 
 


kanishasrathod
confusion
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


Advertisement
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:

#include<stdio.h>
#include<conio.h>
int main()
{
    int num1,num2,sum;
    printf("\nEnter 1st number for addition:");
    scanf("%d",&num1);
    printf("\nEnter 2nd number for addition:");
    scanf("%d",&num2);
    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);
    getch();
    return 0;
}


Related Tutorials/Questions & Answers:
 

 

 

DMCA.com