Search
 
SCRIPT & CODE EXAMPLE
 

C

swap two numbers without third variable

int a=4;
int b=5;
a=a+b; // 4 + 5 = 9
b=a-b; // 9 - 5 = 4
a=a-b; // 9 - 4 = 5
Comment

swap without using third variable

// SWAPPING WITHOUT USING THIRD VARIABLE
#include<stdio.h>  
 int main()    
{    
int a=10, b=20;      
printf("Before swap a=%d b=%d",a,b);      
a=a+b;//a=30 (10+20)    
b=a-b;//b=10 (30-20)    
a=a-b;//a=20 (30-10)    
printf("
After swap a=%d b=%d",a,b);    
return 0;  
}   
Comment

swap 2 numbers without using 3rd variable

a=10;
b=20;
a=a+b;//a=30 (10+20)    
b=a-b;//b=10 (30-20)    
a=a-b;//a=20 (30-10)    
Comment

swap of two numbers without using third variable

a=20;
b=40;
a=a+b;  
b=a-b;
a=a-b;  
Comment

how to swap 2 numbers without 3rd variable

int a = 3;
int b = 5;
a = b*a;
b = a/b
a = a/b
Comment

swapping data of two variable without third one

X= 25 (First number), Y= 23 (second number)
Swapping Logic:
X = X + Y = 25 +23 = 48
Y = X - Y = 48 - 23 = 25
X = X -Y = 48 - 25 = 23
and the numbers are swapped as X =23 and Y =25.
Comment

Swapping Two Numbers Using Third Variable

   public static void main(String[] args) {
        int x = 10;
        int y = 20;
        int temp;

        temp = x;
        x = y;
        y = temp;

        System.out.println("x:"+x  +" y:" + y);
    }
Comment

Swapping Variables

x = 10
y = 11


x, y = y, x
"Swapping by simultaneously creating a tuple and unpacking it"

print(x, y)
Comment

swap two numbers without using third variable

var a=window.prompt('enter a number')var b=window.prompt('enter a number')var a=a+b;var b=a-b;var a=a-b;console.log ("value of a is",a);console.log('value of b is',b);
Comment

Swapping Two Numbers without Using Third Variable

    public static void main(String[] args) {
        int x = 10;
        int y = 20;
        
        x=x+y;
        y=x-y;
        x=x-y;

        System.out.println("x:"+x+" y:"+y);
    }
Comment

Swapping two variable without initializing the third variable

#include <iostream>
using namespace std;
int main()
{
    int first_number = 10, last_number = 20;
    first_number = first_number + last_number;
    last_number = first_number - last_number;
    first_number = first_number - last_number;
    cout << first_number << " " << last_number << endl;
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: XAudio2 C 
C :: can we use logical operators in switch c 
C :: obstacle avoiding robot in c++ program 
C :: float da 4 byte 
C :: Here is a program in C that illustrates the use of fprintf() to write a text file: 
C :: vscode how to output in seperate consile 
C :: how tier lists work 
C :: c fibonacci series recursion 
C :: ansi c write unsigned short to file 
C :: c %d 
C :: how to link flexslider 
C :: diamond dataset in r 
C :: until command lldb 
C :: temperature sensor data 
C :: c to assembly converter online 
C :: bc1q9rfht42zayr3yvxqjw8tm6v3tkwl93t35gegxl 
C :: which one is faster loop or recursive function? 
C :: determination data type in c 
C :: Integer Input/Output 
C :: send array to child process c 
C :: captive portal esp8266 
C :: C fgets() and puts() 
C :: finding average of elements in array using struct in C? 
C :: params in main function in C 
C :: how to get value of multidimensional array in c 
C :: open cv 
Dart :: flutter elevated button radius 
Dart :: how to make a column scrollable in flutter 
Dart :: flutter card border radius overflow hidden 
Dart :: file picker flutter file size 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =