.Net Practical 4

Practical : 4
Subject : .Net

Aim : C# code to Perform Celsius to Fahrenheit Conversion and Fahrenheit to Celsius conversion.

Source Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace pr008
{
    class temprature
    {
        static void Main(string[] ar)
        {
            string y;
            do
            {
                Console.WriteLine("1)C->F   2)F->C  3)C->K");
                Console.Write("Enter Choice : ");
                int i = Convert.ToInt32(Console.ReadLine());
                switch (i)
                {
                    case 1:
                        Console.Write("Enter Temprature in C : ");
                        int c = Convert.ToInt32(Console.Read());
                        int f = (c * (9 / 5)) + 32;
                        Console.WriteLine("Temprature is : " + f + "F");
                        break;
                    case 2:
                        Console.Write("Enter Temprature in F : ");
                        f = Convert.ToInt32(Console.Read());
                        c = (f - 32) / (9 / 5);
                        Console.WriteLine("Temprature is : " + c + "C");
                        break;
                    case 3:
                        Console.Write("Enter Temprature in C : ");
                        c = Convert.ToInt32(Console.Read());
                        int k = c + 273;
                        Console.WriteLine("Temprature is : " + c + "K");
                        break;
                }
                Console.Write("Do You Want to Continue (Y/N)? : ");
                y = Console.ReadLine();
            } while (y == "Y" || y == "y");
            Console.Read();
        }
    }
}
Output :

Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment