How to swap two numbers using function C#

1 Answer

0 votes
using System;

class Program
{
    static int swap(int a, int b) {
       return a;
    }

    static void Main()
    {
        int a = 4, b = 1;
        
        a = swap(b, b = a);

        Console.Write(a + " " + b); 
    }
}



/*
run:

1 4

*/

 



answered Apr 30, 2019 by avibootz

Related questions

1 answer 174 views
1 answer 577 views
1 answer 165 views
1 answer 199 views
5 answers 321 views
321 views asked Aug 22, 2022 by avibootz
1 answer 200 views
...