Recent

Thursday, December 30, 2021

December 30, 2021

C# Hello World - Your First C# Program

 C# Hello World - Your First C# Program


The “Hello World!” program is often the first program we see when we dive into a new language. It simply prints Hello World! on the output screen.


  
using System;

public class HelloWorld
{
    public static void Main(string[] args)
    {
        Console.WriteLine ("Hello Mono World");
    }
}
  

Output

Hello World!

Wednesday, December 29, 2021

December 29, 2021

C# Program to Check Whether the Entered Year is a Leap Year or Not





This is a C# Program to check whether the entered year is a leap year or not.

Problem Description

This C# Program Checks Whether the Entered Year is a Leap Year or Not.

Problem Solution

When A year is divided by 4. If the remainder becomes 0 then the year is called a leap year.

Program/Source Code

Here is the source code of the C# Program to Check Whether the Entered Year is a Leap Year or Not. The C# program is successfully compiled and executed with Microsoft Visual Studio. 

  
using System;
public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Enter Year : ");  
        int Year = int.Parse(Console.ReadLine());  
        if (((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0)) 
            Console.WriteLine("{0} is a Leap Year.", Year);  
        else 
            Console.WriteLine("{0} is not a Leap Year.", Year);  
        
        Console.ReadLine();  
    }
}
  
December 29, 2021

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.

Program/Source Code

Here is the source code of the C# program that swaps two numbers. The C# program is successfully compiled and executed with Microsoft Visual Studio. 


  
  /*
 * C# Program to Swap two Numbers
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
    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();
        }
    }
}
  

Tuesday, December 28, 2021

December 28, 2021

C# Program to Check whether the Entered Number is Even or Odd



 This is a C# Program to check whether the entered number is even or odd.

Problem Description

This C# Program checks if a given integer is Odd or Even.

Problem Solution

Here if a given number is divisible by 2 with the remainder 0 then the number is an Even number. If the number is not divisible by 2 then that number will be an Odd number.

Program/Source Code

Here is source code of the C# program which checks a given integer is odd or even. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.


/*
 * C# Program to Check whether the Entered Number is Even or Odd
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            Console.Write("Enter a Number : ");
            i = int.Parse(Console.ReadLine());
            if (i % 2 == 0)
            {
                Console.Write("Entered Number is an Even Number");
                Console.Read();
            }
            else
            {
                Console.Write("Entered Number is an Odd Number");
                Console.Read();
            }
        }
    }
}

DONT CLICK THIS - https://bit.ly/3F3Glqn