In this program, int a,b,c statement declares 3 variables named as a,b & c . The 2 values
are entered by user because of scanf statement & stored in a & b which are the no. to be
swapped . Now, c variable is a temporary variable to store 1st value . Using a = b, 2nd variable
value is now stored in 1st variable then c which stores value of 1st variable is assigned to 2nd
Program to swap using third variable.
are entered by user because of scanf statement & stored in a & b which are the no. to be
Program to swap using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{ int a,b,c;
clrscr();
printf("\nprogram to swap 2 no.s");
printf("\n\nenter value of a :");
scanf("%d",&a);
printf("enter value of b :");
scanf("%d",&b);
c = a;
a = b;
b = c;
printf("\n now value of a = %d",a);
printf("\n now value of b = %d",b);
getch();
}

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.