A
và B
. Yêu cầu in ra màn hình giá trị trước và sau khi thay đổi vị trí của A
và B
.
A
và B
. Sử dụng 1 biến temp
để thay đổi giá trị của 2 biến A
và B
:
temp = A; A = B; B = temp;
/* C# Program to Swap 2 Numbers This is a C# Program to swap 2 numbers. Problem Description This C# Program Swaps 2 Numbers. Problem Solution It obtains two numbers from the user and swaps the numbers using a temporary variable. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lession2 { class Program { static void Main(string[] args) { int num1, num2, temp; Console.Write("\nEnter the First Number : "); num1 = int.Parse(Console.ReadLine()); Console.Write("\nEnter the Second Number : "); num2 = int.Parse(Console.ReadLine()); temp = num1; num1 = num2; num2 = temp; Console.Write("\nAfter Swapping : "); Console.Write("\nFirst Number : " + num1); Console.Write("\nSecond Number : " + num2); Console.Read(); } } }[/su_spoiler]
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!