answersLogoWhite

0


Best Answer

To swap two variables without using a third variable, use exclusive or manipulation...

a ^= b;

b ^= a;

a ^= b;

User Avatar

Wiki User

โˆ™ 2010-06-05 22:08:34
This answer is:
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program in C plus plus plus plus How do you write a program in C to swap two variables without using the third oneo swap two variables without using the third one?
Write your answer...
Submit
Related questions

How do you write a program in C to swap two variables without using the third one using XOR?

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


How do you write a program in Perl to swap two variables without using the third one?

Use list assignment i.e. for two variables $a, $b: ($a,$b) = ($b,$a)


How do you write a program in C to swap two variables without using the third one using pointers?

void swap(int* x, int*y) { (*x)^=(*y)^=(*x)^=(*y); }


C program for swap two numbers without using temporary variables?

A ^= B; B ^= A; A ^= B;


How to Swap two variables without using third variable using pointer?

swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }


When possible you should advoid using what variables in a program?

Global Variables Or: variables with names longer than 128 characters.


Write a program to input two numbers and interchange there value without using the third variable?

health


Cheats on how to get clubpenguin cloths if your not a member?

Without using a third party cheating program, unfortunetly, is impossible.


How can you accept sum and print numbers without creating variables?

It is very easy. The program begins here..... /*Program to sum and print numbers without creating variables*/ #include<stdio.h> main() { clrscr(); printf("%d+%d=%d",5,2,5+2); getch(); } /*Program ends here*/ Now just by changing the numbers in the "printf" statement we can add, subtract, multiply and divide the numbers without using variables. Hence the problem is solved..........


How do you write a program in C to swap two variables without using?

Please note the following coding for the same if the question is How do you write a program in C to swap two variables without using another variables? :- void main() { int a,b; printf("Enter a and b:", a,b); scanf("%d %d",&a,&b); a=a+b; b=a-b; a=a-b; printf(" a=%d and b=%d",a,b); } By: Anil Kothiyal


Why do you use static in java program?

Using on static keyword, we can write static methods and variables. In java static variables accessing class level, and coming to the static methods without creating the object we can access methods.


How do you write java program without using class?

you can not write a java program without using even single class..............


Write an algorithm and flowchart of the exchanging value of two variables?

write a program in c swap two number without using tempry vriable with flochart and algorithum


Can you write addition of 2 no program without using third variable?

Yes. int a, b; a= 2; b= 3; a= a+b;


How do you write a program in C to swap two variables without using the third one - 46k?

int a = 5; int b = 10; a = a + b; // a = 5 + 10 = 15 b = a - b; // b = 15 - 10 = 5 a = a - b; // a = 15 - 5 = 10


How do you write a program in C to swap two variables using the third variable?

Consider the following declarations:int x = 0;int y = 1;In order to swap the values, we need to use a temporary variable:int t = x;x = y;y = t;However, it is possible to swap the values without using a third variable:x ^= y ^= x ^= y;


How can you devise a way to interchange two variables A and B without using a third variable or register using Exclusive OR?

A = A xor B B = A xor B A = A xor B in C... A^=B; B^=A; A^=B;


How do you run program without using editor?

I did not know that a program could be run using editor.


Is it possible to make a program using for and not with while?

The following cases are all possible:- program without any for and while- program without for- program without while- program with both for and while


What is program in c to swap entered two numbers without using third variable?

The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }


Write a program for two variables without using third variable in c plus plus?

#include <stdio.h> int main (void) { char *first= "Hello"; int second = 12; printf ("first=%s, second=%d\n", first, second); return 0; }


How do you swap variables in PHP?

By using a third temporary variable. $tmp = $a; $a = $b; $b = $tmp;


How can a program be written without using a USING instruction?

By using explicit scope resolution.


Program in c using pointers to interchange 2 values without using third variable?

swap (int *pa, int *pb) { *pa ^= *pb; *pa ^= *pa; *pa ^= *pb; }


What is a third party program?

A third-party program is just that, a computer program created by a third-party. In the context of a computer's operating system, a third-party program would be any program not written by you or by the makers of the operating system you're using. For example, if a user was running Windows as their operating system, then a third-party program would be any program not written by you or by Microsoft. Most programs that a person runs on their computer are third-party programs.