diff --git a/swap using 3rd variable.cpp b/swap using 3rd variable.cpp new file mode 100644 index 0000000..37ec3da --- /dev/null +++ b/swap using 3rd variable.cpp @@ -0,0 +1,16 @@ +// Swappint two numbers using third variable + +#include +int main () + +{ + int a,b,x; + printf("enter the value of a and b="); + scanf("%d%d",&a,&b); + x=a; + a=b; + b=x; + printf("values after swapping are a=%d\nand b=%d",a,b); + return 0; + +} diff --git a/swap without using variable.cpp b/swap without using variable.cpp new file mode 100644 index 0000000..97c78ee --- /dev/null +++ b/swap without using variable.cpp @@ -0,0 +1,15 @@ +// Swapping without using third variable + +#include +int main() + +{ + int a,b; + printf("enter the values of a and b = "); + scanf("%d%d",&a,&b); + a=a+b; + b=a-b; + a=a-b; + printf("values after swapping are a=%d \n b=%d",a,b); + return 0; +}