0% found this document useful (0 votes)
4 views7 pages

02

The document contains three C# programs that perform different tasks. The first program checks if a number is odd or even, the second checks if a year is a leap year, and the third calculates an electricity bill based on usage. Each program prompts the user for input and outputs the result accordingly.

Uploaded by

Sarathi M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

02

The document contains three C# programs that perform different tasks. The first program checks if a number is odd or even, the second checks if a year is a leap year, and the third calculates an electricity bill based on usage. Each program prompts the user for input and outputs the result accordingly.

Uploaded by

Sarathi M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1)

Code:

using System;

Class oddoreven

Static void Main()

Console.Write(“Enter a number: “);

int number = int.Parse(Console.ReadLine());

String result = (number % 2 == 0) ? “Even” : “Odd”;

Console.WriteLine(result);

Output:
2)

Code:

using System;
Class LeapYearCheck

Static void Main()

Console.Write(“Enter a year: “);

int year = int.Parse(Console.ReadLine());

bool isLeap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);

Console.WriteLine(isLeap ? “Leap Year” : “Not a Leap Year”);

Output:
3)

Code:
using System;

Class ElectricityBill

Static void Main()

Console.Write(“Enter electricity units: “);

int units = int.Parse(Console.ReadLine());

double billAmount = 0;

int extraCharge = 0;

if (units <= 100)

billAmount = 0;

extraCharge = 0;

Else if (units <= 250)

billAmount = units * 0.80;

extraCharge = 25;

Else if (units <= 450)

billAmount = units * 1.50;

extraCharge = 75;

}
else

billAmount = units * 2.00;

extraCharge = 100;

double total = billAmount + extraCharge;

Console.WriteLine(“Normal Charges: Rs. “ + billAmount);

Console.WriteLine(“Extra Charges: Rs. “ + extraCharge);

Console.WriteLine(“Total Bill: Rs. “ + total);

Output:

You might also like