write a prgram of swapping with 2 valiables
Answers were Sorted based on User's Feedback
Answer / eranna kybarshi
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf("Enter 'x' value :");
scanf("%d",&x);
printf("\nEnter 'y' value :");
scanf("%d",&y);
x=x+y;
y=x-y;
x=x-y;
printf("\nAfter swaping x= %d,y= %d ",x,y);
getch();
}
Is This Answer Correct ? | 20 Yes | 0 No |
Answer / vijay r15
#include<stdio.h>
Void main()
{
int a=10,b=20;
a=a+b-(a=b);
// or use temp var
//or use a^=b^=a
//or use a=a+b;b=a-b;a=a-b;
printf("%d%d",a,b);
}
Any dbt mail to raj.vijay55@gmail.com
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / kumar
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y ;
int z = 0;
clrscr();
printf("Enter 'x' value :");
scanf("%d",&x);
printf("\nEnter 'y' value :");
scanf("%d",&y);
z=x;
x=y;
y=z;
printf("\nAfter swaping x= %d,y= %d ",x,y);
getch();
}
Is This Answer Correct ? | 4 Yes | 2 No |
Answer / aruna.r
#include<stdio.h>
#include<conio.h>
void main()
{
int a=6;
int b=5;
int temp;
temp=a;
a=b;
b=temp;
printf("a & b value %d,%d",a,b);
getch();
}
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / suresh
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
d=0;
printf("enter a");
scanf("%d",&a);
printf("enter b");
scanf("%d",&b);
c=a;
a=b;
b=c;
printf("a & b value are%d%d",a,b);
getch();
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / devi
i can swap da 2 variables in singe instr
main()
{
int a,b;
a=(a=(a+b),b=(a-b),a-b);
-------
-------
}
Is This Answer Correct ? | 0 Yes | 0 No |
How to print "Hi World" without using semi colon?
what are the various memory handling mechanisms in C ?
program to print upper & lower triangle of a matrix
what will happen if you free a pointer twice after allocating memory dynamically ?
can we define a function in structure?
Can a variable be both static and volatile in c?
How do you redirect a standard stream?
write a program to print data of 5 five students with structures?
What is difference between structure and union in c?
what would be the output of the follwing struct st { char name[20]; int i; float f; }; main() { struct st emp = {"forum"}; printf("%d %f",emp.i,emp.f); }
code for bubble sort?
What is the importance of c in your views?