Support us on YouTube by Subscribing our YouTube Channel. Click here to Subscribe our YouTube Channel

Friday 29 January 2021

Program to check whether the entered year is Leap Year or Not

In this example, we will learn How to find the year entered by the user is Leap Year or not. This is one of the most common interview questions which can be asked on the fresher level interview round.


I will recommend you to check the below link for Top C# Interview Programs asked during the Interview and Examination.


Let’s Begin:

In order to find the year entered by the user is Leap year or not, we have to check first that the year entered by the user is evenly divisible by 4. If the year is evenly divisible by 4 as well as evenly divisible by 100 then the year entered by the user is not a Leap year. In case if it's not evenly divisible by 100 then it is an example of Leap year. In case, If the year is evenly divisible by 400 then this is an example of the Leap year.

Program:

Console.WriteLine("Enter the year to check whether year entered is Leap year or not?");

//Recieve input year from the user

int yearValue = Convert.ToInt32(Console.ReadLine());

//If year is evenly divisible by 4 as well and not divisible by 100 then year is leap year

//If year is evenly divisible by 400 then year is leap year

//Else not a Leap Year

if ((yearValue % 4 == 0 && yearValue % 100 != 0) || (yearValue % 400 == 0))

{

    Console.WriteLine("{0} is a Leap Year", yearValue);

}

else {

    Console.WriteLine("{0} is not a Leap Year", yearValue);

}

//Using Console.ReadLine() in order to hold the terminal/command prompt

Console.ReadLine();

Preview:





I hope this example will help you in your interview/exam preparation.
Thanks

Saturday 23 January 2021

Program to Count Vowels and Consonants in a string

One of the popular programs which can be asked by the interviewer during the interview is to count no. of Vowels and Consonants in a string. The letters A, E, I, O, and U are called Vowels and the other letters (except vowels) in the alphabet are known as Consonants.

Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook