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
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none
Are there any problems with performing mathematical operations on different variable types?
What are structure types in C?
What is use of null pointer in c?
Is there a way to jump out of a function or functions?
What is sizeof array?
How can you determine the size of an allocated portion of memory?
Explain what does a function declared as pascal do differently?
What do you mean by dynamic memory allocation in c? What functions are used?
What are local variables c?
Explain how do you determine a file’s attributes?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
What is #define in c?
What are the types of pointers?
What is function prototype?