Posts

Showing posts with the label c++

Swapping using third variable in c and c++ and any language use logic.

Image
 Swapping using third variable in c,c++,java and any language use logic....... // swapping using third variable. #include<stdio.h> #include<conio.h> void main(){     int a,b,c;     clrscr();     printf("Enter the value of a=\t");     scanf("%d",&a);     printf("Enter the value of b=\t");     scanf("%d",&b);     printf("before swapping\n");     printf("a is=%d",a);     printf("\nb is=%d\n",b);     c=a;     a=b;     b=c;     printf("after swapping\n");     printf("a is=%d\n",a);     printf("b is=%d",b);     getch(); } Divanshu Sindhwani

Swapping without using 3rd variable in c and c++ and any language use logic

Image
Swapping  without  using third variable in c,c++,Java,JavaScript and any language logic.... // swapping without third variable. #include<stdio.h> #include<conio.h> void main(){     int a,b;     clrscr();     printf("Enter the value of a=\t");     scanf("%d",&a);     printf("Enter the value of b=\t");     scanf("%d",&b);     printf("before swapping\n");     printf("a is=%d",a);     printf("\nb is=%d\n",b);     a=a+b;     b=a-b;     a=a-b;     printf("after swapping\n");     printf("a is=%d\n",a);     printf("b is=%d",b);     getch(); } Divanshu Sindhwani