Search
 
SCRIPT & CODE EXAMPLE
 

C

swap 2 integers without using temporary variable

using System;

class MainClass {
  public static void Main (string[] args) {
    int num1 = int.Parse(Console.ReadLine());
    int num2 = int.Parse(Console.ReadLine());
      num1 = num1 + num2; 
      num2 = num1 - num2; 
      num1 = num1 - num2; 
      Console.WriteLine("After swapping: num1 = "+ num1 + ", num2 = " + num2); 
    Console.ReadLine();
  }
}
Comment

Program to Find Swap Numbers Using Temporary Variable

#include<stdio.h>

int main() {
   int x, y, temp;
   printf("Enter the value of x and y: ");
   scanf("%d %d", &x, &y);
   printf("Before swapping x=%d, y=%d ", x, y);
    
   /*Swapping logic */   temp = x;
   x = y;
   y = temp;
   printf("After swapping x=%d, b=%d", x, y);
   return 0; 
}
Program Output:
Comment

PREVIOUS NEXT
Code Example
C :: bc1q9rfht42zayr3yvxqjw8tm6v3tkwl93t35gegxl 
C :: 157.245.33.77: 
C :: Entering raw mode 
C :: UTC offset upper limit 
C :: pre-commit configuration 
C :: convert c code to c online 
C :: if statement shortcut c 
C :: How to open terminal cs50 ide 
C :: command to perform safe shutdown in unix 
C :: WAP to create Database using array of structure & display it in C 
C :: deepak rake 
C :: c check if character is a punctuation 
C :: String insertion into another string 
C :: unconstrained box flutter 
C :: how to use arry 
C :: comando para ejecutar hilos en c 
C :: Word Processor, Spreadsheet and Presentation Software are the examples of 
C :: else if statement in c 
C :: time now C 
C :: in c check if triangle is a right triangle 
Dart :: flutter validate email 
Dart :: flutter format currency fcfa 
Dart :: media query width flutter 
Dart :: open link with button flutter 
Dart :: file picker flutter file size 
Dart :: drawer corner radius flutter 
Dart :: dart to double 
Dart :: flutter cut string 
Dart :: flutter popupmenubutton 
Dart :: dart regex for url 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =