You are on page 1of 3

MALAYSIAN INSTITUTE OF INFORMATION TECHNOLOGY UNIVERSITI KUALA LUMPUR C# PROGRAMMING

Name : LAB 1 Date : TOPIC : INTRODUCTION TO C#

Objective: At the end of the session, student will be able to Write a simple program Visual C# Understand the use of namespace, class Learn how to use comment Write a program that requires user input Convert a commonly used data type Write, compile and run the program Filename : LabExercise1Q1 Welcome to C#

using System; namespace LabExercise1Q1 { class Question1 { public static void Main(string[] args) { Console.Write(" Welcome to C# Programming\n"); Console.Write("\t C# is interesting !"); Console.ReadLine(); } } }

Filename : LabExercise1Q2

Formatting output display

using System; namespace LabExercise1Q2 { class Question2 { public static void Main(string[] args) { string name="Ibnu Sina"; Console.WriteLine("Hello{0}...",name); Console.WriteLine(" This is very easy "); Console.ReadLine(); } } }

ITD10903 C#Programming

-1-

Filename : LabExercise1Q3

Performing simple operation

using System; namespace LabExercise1Q3 { class Question3 { public static void Main(string[] args) { int width=5, length=10; float area; area=width*length; Console.WriteLine("The area is {0}",area); Console.ReadLine(); } } }

Filename : LabExercise1Q4

Calculate the volume of cylinder

Write a program that accepts two integer values. Calculate and display the average. Calculate_average Prompt num1 , num2 Get num1 , num2 average (num1 + num2)/2 Display average END

using System; namespace LabExercise1Q4 { class Question4 { public static void Main(string[] args) { int num1 , num2; float average; Console.WriteLine("Enter first number: "); num1 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter second number: "); num2 = int.Parse(Console.ReadLine()); average = (num1 + num2)/2; Console.WriteLine("The average is {0}",average); Console.ReadLine(); } } }

Filename : LabExercise1Q5

Calculate the volume of cylinder

ITD10903 C#Programming

-2-

A program is required to calculate a volume of a cylinder. By referring to the figure below, prompt user to enter base radius and height of the cylinder. Calculate and display the volume with the following formula :
radius

height

Cylinder volume = 3.142 * radius * radius * height Filename : LabExercise1Q6 Calculate the BMI

A quantity known as the body mass index (BMI) is used to calculate the risk of weight-related health problems. BMI is computed by the formula BMI = w / (h / 100.0)2 where w is weight in kilograms and h is height in centimeters. Write a program that received input from user and display the BMI Filename : LabExercise1Q7 Movie ticket

On Wednesday, Che Yah wants to watch a movie. When she arrived at the cinema, she was told that Wednesday is a Ladies Day and each ticket will get 10% less from the actual price. Calculate and display the each ticket price she has to pay. Filename : LabExercise1Q8 Part time income

Prompt the part time worker in McDonald to enter hours work. Write a program to calculate and display the total salary (for one day) for a part time worker if the worker is paid RM3.70 per hour. Notes

ITD10903 C#Programming

-3-

You might also like