Problem Analysis:
The problem is to swap the variables values with and without using third variables having parameters a,b,c,d,e .
The output is to print the variables by swapping.
Input variables processing variables Output variables Necessary header file
a(int) c=a a(int) stdio.h
b(int) a=b b(int) conio.h
d(int) b=c d(int)
e(int) d=d+e; e(int)
e=d-e;
d=d-e;
Algorithms:
1.start
2.Input the variables by the user.
i.e. int a ,b,d,e
3.Swapping the values with and without using the 3rd variables.
such as: c=a; d=d+e;
a=b; e=d-e;
b=c; d=d-e;
4.Print the outputs a ,b,d and e ;
5.End
Flowcharts:
fig: flowchart to swap the numbers.
Codes:
/*program to swap two variables values with and without using third variables*/
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,d,e;
printf(” enter a ,b,d,e:”);
scanf(“%d%d%d%d”,&a,&b,&c,&d:);
printf(“before swapping:%d%d”,a,b);
c=a;
a=b;
b=c;
printf(“after swapping:%d%d”,a,b);
printf(“before swapping:%d%d”,d,e);
d=d+e;
e=d-e;
d=d-e;
printf(“after swapping:%d%d”,d,e);
getch();
return 0;
}
Outputs:
(Compiling , Debuggings and Testings)
enter a ,b,d,e : 3 4 6 8
before swapping: 3 4
after swapping : 4 3
before swapping : 6 8
after swapping : 8 6