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
How can you restore a redirected standard stream?
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above
How can you increase the allowable number of simultaneously open files?
What is the difference between a string and an array?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
What is quick sort in c?
What are the types of data structures in c?
How can I delete a file?
How do c compilers work?
How do you print an address?
Why is struct padding needed?
What is a pointer on a pointer in c programming language?
Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix
Write a code to determine the total number of stops an elevator would take to serve N number of people.