Answer to Question #243102 in C# for Gayatri

Question #243102

1. Write a C# Sharp program to print Hello and your name in a separate line.


2. Given a temperature in Celsius degrees, write a method that converts it to Fahrenheit degrees.


3. Given two integers, write a method that swaps them using temporary variable.


4. Given an integer, write a method that checks if it is even.


5. Given a number, write a method that checks if it is positive, negative or zero.


6. Given a year as integer, write a method that checks if year is leap.


1
Expert's answer
2021-10-01T07:45:52-0400
// 1
using System;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello");
            Console.WriteLine("Name");
        }
    }
}
// 2
using System;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static double CelsiusToFarenheit(double c)
        {
            return c * 9 / 5 + 32;
        }
        public static void Main(string[] args)
        {
            Console.WriteLine(CelsiusToFarenheit(10));
        }
    }
}
// 3
using System;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var num1 = int.Parse(Console.ReadLine());
            var num2 = int.Parse(Console.ReadLine());

            int temp;

            temp = num1;
            num1 = num2;
            num2 = temp;
            
            Console.WriteLine($"{num1} {num2}");
        }
    }
}
// 4
using System;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            
            if (num % 2 == 0)
                Console.WriteLine("Even");
            else
                Console.WriteLine("Odd");
        }
    }
}
// 5
using System;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            
            if (num > 0)
                Console.WriteLine("Positive");
            else if (num < 0)
                Console.WriteLine("Negative");
            else
                Console.WriteLine("Zero");
        }
    }
}
// 6
using System;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var year = int.Parse(Console.ReadLine());
            
            if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
                Console.WriteLine("Leap");
            else
                Console.WriteLine("not leap");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS