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


Please Help Members By Posting Answers For Below Questions

What is pass by value in c?

591


Why is c so important?

586


Who developed c language?

630


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

634


What are the various types of control structures in programming?

619






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?

972


What is a loop?

546


what are enumerations in C

716


What is && in c programming?

669


How can you check to see whether a symbol is defined?

583


Why is structure padding done in c?

635


How do you determine whether to use a stream function or a low-level function?

636


What is the purpose of sprintf?

608


What are the advantage of c language?

542


What is a lvalue

653