write a program to swap Two numbers without using temp variable.
Answer Posted / ankit
#include<stdio.h>
void swap(int *,int *);
void main()
{
int a,b;
clrscr();
printf("enter two numbers");
scanf("%d%d",&a,&b);
swap(&a,&b);
/* b=(a+b)-(a=b); 1st method */
/* 2nd method
a=a+b;
b=a-b;
a=a-b; */
/* 3rd Method
a=a*b;
b=b/a;
a=a/b; */
/*4th Method
a=a^b;
b=b^a;
a=a^b; */
/* 5th Method
using pointer*/
printf("a=%d\nb=%d",a,b);
getch();
}
void swap(int *a,int *b)
{
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is sizeof array?
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above
What is getch?
How can you return multiple values from a function?
What is a MAC Address?
A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM
a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f
What is #line?
Can we declare function inside main?
Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?
What are loops c?
What are the types of data types and explain?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above
What is the use of extern in c?