Answers for "Program to Find Swap Numbers Using Temporary Variable"

C
0

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();
  }
}
Posted by: Guest on September-23-2020
0

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:
Posted by: Guest on February-22-2022

Code answers related to "Program to Find Swap Numbers Using Temporary Variable"

Code answers related to "C"

Browse Popular Code Answers by Language