1. Create a button control that has the caption Close. Now write the code which will ask the user to confirm whether he wants to close the program when he clicks on the Close button.
2. Write a program that requests the user to input two numbers and select an arithmetic operator. The program will then perform the calculation using the selected operator. (Use the Switch construct)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter first number: ");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter second number: ");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter operation: ");
string op = Console.ReadLine();
switch (op)
{
case "+": Console.WriteLine("{0} + {1} = {2}", a, b, a + b);break;
case "-": Console.WriteLine("{0} - {1} = {2}", a, b, a - b); break;
case "*": Console.WriteLine("{0} * {1} = {2}", a, b, a * b); break;
case "/": Console.WriteLine("{0} / {1} = {2}", a, b, a / (double)b); break;
}
Console.ReadLine();
}
}
}
Comments
Leave a comment