snow

Blogger Widgets

Thursday, November 15, 2012

c-program to swap two numbers without using arithmetic operators


gowrikausalya.blogspot.com

/*c-program to two numbers without using arithmetic operators*/

#include<stdio.h>
#include<conio.h>
int main()
{
    int a,b;
    printf("Enter two numbers :");
    scanf("%d%d",&a,&b);
    printf("Before swapping..\n\n");
    printf("A=%d\nB=%d",a,b);
    a= a ^ b;
    b= a ^ b;
    a= a ^ b;
    printf("\n\nAfter swapping ...\n");
    printf("A=%d\nB=%d",a,b);
    getch();
}

Output:-

you may also like to see

c-program to swap using third variable


gowrikausalya.blogspot.com

/*c-program to swap two numbers using third variable */


#include<stdio.h>
#include<conio.h>
int main()
{
    int a,b,c;
    printf("Enter two numbers :");
    scanf("%d%d",&a,&b);
    printf("Before swapping..\n\n");
    printf("A=%d\nB=%d",a,b);
    c=a;
    a=b;
    b=c;
    printf("\n\nAfter swapping (using 3rd variable)...\n\n");
    printf("A=%d\nB=%d",a,b);
    getch();
}

OUTPUT
gowrikausalya.blogspot.com



c-program to swap two numbers using two variables

gowrikausalya.blogspot.com

/*c-program to swap two numbers using two variables*/

#include<stdio.h>
#include<conio.h>

int main()
{
    int a,b;
    printf("Enter two numbers :");
    scanf("%d%d",&a,&b);
    printf("Before swapping..\n\n");
    printf("A=%d\nB=%d",a,b);
    a=a+b;
    b=a-b;
    a=a-b;
    printf("\n\nAfter swapping ...\n");
    printf("A=%d\nB=%d",a,b);
    getch();
}
output:-




you may also like to see
(1).swapping using third variable...
(2).swapping without using arithmetic operators...