Ad Code

Responsive Advertisement

Swapping two numbers using third variable

 

 C program for Swapping two numbers using third variable

Swapping Numbers using third variable

C Program:

Output 1:

swapping two numbers

From the above program,

ü Let a=7 and b=5.

ü Let c be the third variable used for swapping the numbers.

c=a

a=b

b=c

c=7

a=5

b=7

ü a's value will be first assigned to the variable c, then b's value assigned to the a variable, now b's value overwrites the a's value.

ü now b's value will be overwritten by the c's value which is actually the a's value.


Post a Comment

0 Comments

Close Menu