C PROGRAM TO SWAP TWO NUMBERS.
In this example,
we will learn how to swap two numbers using third variable.
FLOWCHART TO SWAP TWO NUMBERS:
PROGRAM:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the value of a : ");
scanf("%d",&a);
printf("Enter the value of b : ");
scanf("%d",&b);
printf("\nBefore swapping values of a=%d and b=%d",a,b);
c=a;
a=b;
b=c;
printf("\nAfter swapping values of a=%d and b=%d",a,b);
}
OUTPUT:
C PROGRAM TO SWAP TWO NUMBERS WITHOUT USING THIRD VARIABLE.
Here, we will see how to swap two
numbers without using third variable.
FLOWCHART TO SWAP TWO NUMBERS WHITHOUT USING THIRD VARIABLE:
PROGRAM:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter the value of a : ");
scanf("%d",&a);
printf("Enter the value of b : ");
scanf("%d",&b);
printf("\nBefore swapping values of a=%d and b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping values of a=%d and b=%d",a,b);
}
OUTPUT:
Comments
Post a Comment
Please do not spam any link