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 the difference between mpi and openmp?
what are bit fields? What is the use of bit fields in a structure declaration?
Why is c so important?
Simplify the program segment if X = B then C ← true else C ← false
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
When should the const modifier be used?
What does the format %10.2 mean when included in a printf statement?
What is main function in c?
What are the c keywords?
What does. int *x[](); means ?
I have seen function declarations that look like this
hi any body pls give me company name interview conduct "c" language only
Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?
What do you mean by Recursion Function?