For Developers

Swapping a Number

SWAPPING WITHOUT TEMP:


#include <stdio.h>

void main()

{

int a=20,b=30;

a=a+b;

b=a-b;

a=a-b;

printf("a=%d",a);

printf("b=%d",b);

}


SWAPPING WITH TEMP:


#include <stdio.h>

void main()

{

int a=20,b=30,temp;

temp=a;

a=b;

b=temp;

printf("a=%d",a);

printf("b=%d",b);

}


0 comments:

Post a Comment