Write a program to interchange two variables without using
the third variable?
Answers were Sorted based on User's Feedback
Answer / guest
#include<stdio.h>
void main()
{
int x,y;
printf("enter x and y");
scanf("%d%d",&x,&y);
x=x+y;
y=x-y;
x=x-y;
printf("elements after swapping :%d,%d",x,y);
}
Is This Answer Correct ? | 185 Yes | 32 No |
Answer / jisha. k.a
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a-b;
b=a+b;
a=b-a;
printf("After chanching no is =\n");
printf("a=%d b=%d",a,b);
getch();
}
Is This Answer Correct ? | 34 Yes | 16 No |
Answer / vinay tiwari
void main()
{
int a,b;
printf("enter two no ");
scanf("%d%d",&a,&b);
printf("a=%d and b=%d",a,b);
a=a^b;
b=a^b;
a=a^b;
printf("a=%d and b=%d",a,b);
getch();
}
Is This Answer Correct ? | 22 Yes | 13 No |
Answer / saravanan j (srm universi
you can apply it on any language?!
x = x xor y
y = x xor y
x = x xor y
* 1 year ago
Source(s):
Self Expierince
Is This Answer Correct ? | 18 Yes | 12 No |
Answer / debasis nayak
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the value of A and B");
scanf("%d %d",&a,&b);
b=(a+b-a=b);
printf("After interchange value are %d %d",a,b);
getch();
}
Is This Answer Correct ? | 11 Yes | 13 No |
Answer / genius
#include <stdio.h>
#include <conio.h>
main()
{
int a,b,temp;
clrscr();
printf("enter two numbers:");
scanf("%d,%d",&a,&b);
printf("values of a and b are %d,%d \n",a,b);
temp=a;
a=b;
b=temp;
printf("swapped values of a and b are %d,%d", a,b);
getch();
}
Is This Answer Correct ? | 4 Yes | 6 No |
Answer / tom macdonald
#include<stdio.h>
void main()
{
int x,y;
printf("enter x and y: ");
scanf("%d%d",&x,&y);
x^=y;
y^=x;
x^=y;
printf("elements after swapping: %d,%d\n",x,y);
}
Is This Answer Correct ? | 29 Yes | 32 No |
Answer / raghavendra
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a*b;
b=a/b;
a=a/b;
printf("After chanching no is =\n");
printf("a=%d b=%d",a,b);
getch();
}
Is This Answer Correct ? | 6 Yes | 9 No |
Answer / pari
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter two no");
scanf("%d%d",&a,&b);
a=a*b;
b=a/b;
a=a/b;
printf("After chanching no is =\n");
}
Is This Answer Correct ? | 4 Yes | 7 No |
Answer / vijay r15
using many ways we can
perform
#include<stdio.H>
void main()
{
int a=10,b=20;
b=a+b-(a=b);
//or use a^=b^=a^=b;
//or use a=a+b;b=a-
b;a=a-b;
//or use a^=b; b^=a;
a^=b;
printf("%d%d",a,b);
}
Is This Answer Correct ? | 2 Yes | 5 No |
What is string length in c?
What is the use of pointers in C?
0 Answers Impetus, Motorola, Tavant Technologies, Virtusa,
What are the ways to a null pointer can use in c programming language?
How to develop software using "c" programming?
Do you know the use of fflush() function?
18)struct base {int a,b; base(); int virtual function1(); } struct derv1:base{ int b,c,d; derv1() int virtual function1(); } struct derv2 : base {int a,e; } base::base() { a=2;b=3; } derv1::derv1(){ b=5; c=10;d=11;} base::function1() {return(100); } derv1::function1() { return(200); } main() base ba; derv1 d1,d2; printf("%d %d",d1.a,d1.b) o/p is a)a=2;b=3; b)a=3; b=2; c)a=5; b=10; d)none 19) for the above program answer the following q's main() base da; derv1 d1; derv2 d2; printf("%d %d %d",da.function1(),d1.function1(),d2.function1 ()); o/p is a)100,200,200; b)200,100,200; c)200,200,100; d)none 20)struct { int x; int y; }abc; you can not access x by the following 1)abc-->x; 2)abc[0]-->x; abc.x; (abc)-->x; a)1,2,3 b)2&3 c)1&2 d)1,3,4
What is an auto keyword in c?
What does main () mean in c?
write an algorithm to get a sentence and reverse it in the following format: input : I am here opuput: Here Am I note: first letter of every word is capiatlised
main() {int a=200*200/100; printf("%d",a); }
what is the output of the code and how? main() { int *ptr,x; x=sizeof(ptr); printf("%d",x); }
write a C program : To find out the number of identical words in two files . the file name should be taken as command line argument .