UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Write a programme to swap two numbers with out using a third variable and by using bitwise op-erators.

Asked by Last Modified  

Follow 0
Answer

Please enter your answer

Computer Science Tutor

a=a+b // a*b // a^b b=a-b // a/b // b^a a=a-b // a/b // a^b
Comments

Take a demo class and you will know

/* Swap a and b */ a ^= b ^= a ^= b ;
Comments

Tuition Classes

main(){ int a=5,b=10; printf("\r\n Before Swap"); printf("\r\na=%d and b=%d",a,b); a^=b^=a^=b; printf("\r\n After Swap"); printf("\r\na=%d and b=%d",a,b); return 0; }
Comments

Technical Corporate Trainer

User XOR ( ^ ) x = x ^ y; y = x ^ y; x = x ^ y;
Comments

SUDHIR SHARMA - Computer Trainer based On Hyderabad

Hi, Ranjeeth.... It's very simple.. just open the following link... http://includehelp.com/c-programs/c-bitwise-programs-to-swap-two-numbers-using-bitwise-operator.aspx
Comments

Tutor

a=a^b; b=a^b a=a^b
Comments

Computer Teacher

import java.io.*; class swap{ public static void main(String args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter 1st no: "); int x=Integer.parseInt(br.readLine()); System.out.print("Enter...
read more
import java.io.*; class swap{ public static void main(String args[]) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter 1st no: "); int x=Integer.parseInt(br.readLine()); System.out.print("Enter 2nd no: "); int y=Integer.parseInt(br.readLine()); System.out.println("\nNumbers Before Swapping:"); System.out.println("x = "+x); System.out.println("y = "+y); //Swapping Method 2 x = x^y; y = x^y; x = x^y; System.out.println("\nNumbers After Swapping:"); System.out.println("x = "+x); System.out.println("y = "+y); } } read less
Comments

Expert in ECE skill set.

Int a; Int b; a=a+b; b=a-b; a=a-b; Printf("a=?d b=%d", a,b); ----- take two numbers and check
Comments

Tutor

a = a-b b = a+b a = b-a
Comments

XOR of 10 (In Binary 1010) and 5 (In Binary 0101) is 1111 and XOR of 7 (0111) and 5 (0101) is (0010).So the code is --------------------------------------- int x = 10, y = 5; x = x ^ y; // x now becomes 15 (1111) y = x ^ y; // y becomes 10 (1010) x = x ^ y; // x becomes 5 (0101)
Comments

View 23 more Answers

Related Questions

How do I add two large integer numbers in C?
We have long int datatype in c programming so use it
Krishan
0 0
6
What are the flaws of the C programming language?
The C programming language, while powerful and widely used, has some inherent flaws. One notable limitation is its lack of built-in support for dynamic memory management and bounds checking. This can lead...
Sounak
0 0
7
What is #line used for?
# is a preprocessor directive. so it is used in the c program by two way. 1. such as #include stdio.h In this line to read all the library function of stdio.h before processing the program. 2. # define...
Pradeep
What is C language?
C is a versatile and powerful procedural programming language developed by Dennis Ritchie at Bell Labs in the early 1970s. Known for its simplicity, efficiency, and low-level access to memory, C has become...
Vikram
0 0
7
Which is the best software for working with C language?
Choosing the "best" software for working with the C language can depend on your specific needs and preferences, but a widely used and reliable option is the GNU Compiler Collection (GCC). GCC is an open-source...
Kiran
0 0
6

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

How do i get best Campus / Off Campus Placement?
Companies are looking for Skilled Freshers. So build your technical skills while doing MCA / BTech / BCA / BSc (IT or CS) into below areas- 1. Strong your programming & debugging skills ...

Static and dynamic libraries
A library is a package of code that is meant to be reused by many programs. A static library (also known as an archive) consists of routines that are compiled and linked directly into your program. When...

C Language
To get help in C window (for keywords, functions) press Alt +F1.To delete a single line , use the shortcut key CTRL +Y.If you got error about the path when you execute a C pgm, check the Options menu =>Directories.
T

Thilagam S.

0 0
0

C for Begginers
C is an procedure oriented programming language. For any begginer the word program is new. Program: Set of instructions to be followed by machine or computer. Instruction Examples: Arithmetic instruction...

Operators in C
Operators in C Operator: An operator is a symbol that tells the compiler to perform certain mathematical or logical calculations. Operators are used in programs to manipulate data and variables. The...

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more