Answers for "swap without third variable in c"

C
0

c program for swapping of two numbers using temporary variable

#include <stdio.h>
int main()
{
    int a, b, temp;
    printf("enter the values of a and b: n");
    scanf("%d%d", &a, &b );
    printf("current values are:n a=%dn b=%dn", a, b);
    temp=a;
    a=b;
    b=temp;
    printf("After swapping:n a=%dn b=%dn", a, b);
}
Posted by: Guest on April-19-2021
0

C Programming to swap two variables

#include <stdio.h>

int main()
{
    int x = 20, y = 30, temp;
    temp = x;
    x = y;
    y = temp;
    printf("X = %d and Y = %d", x, y);
    
    return 0;
}
Posted by: Guest on June-28-2021
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

Code answers related to "swap without third variable in c"

Code answers related to "C"

Browse Popular Code Answers by Language