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 pass by value in c?
Why is c so important?
Who developed c language?
A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile
What are the various types of control structures in programming?
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?
What is a loop?
what are enumerations in C
What is && in c programming?
How can you check to see whether a symbol is defined?
Why is structure padding done in c?
How do you determine whether to use a stream function or a low-level function?
What is the purpose of sprintf?
What are the advantage of c language?
What is a lvalue