Saturday, September 17, 2011

Swap two integers without using a third

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Collections
Public Class Tester
    Public Shared Sub Main
        
        Dim firstValue As Integer
        Dim secondValue As Integer

        firstValue = 17
        secondValue = 123
        Console.WriteLine("Before swap: {0}, {1}",firstValue, secondValue)

        firstValue = firstValue Xor secondValue
        secondValue = firstValue Xor secondValue
        firstValue = firstValue Xor secondValue
        Console.WriteLine("After swap: {0}, {1}",firstValue, secondValue)
    End Sub
End Class

No comments:

Post a Comment

Explain the different parts that constitute ASP.NET application.

Content, program logic and configuration file constitute an ASP.NET application. Content files Content files include static text, images ...