CP Assignment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

BAHRIA UNIVERSITY,

(Karachi Campus)
Department of Software Engineering
ASSIGNMENT#01 – Fall 2020

Course Title: Computer Programming Course Code: CSC-113


Class: BSE – 1(A, B) Deadline: 01-Nov-2020
Course Instructor: ENGR. M. ADNAN UR REHMAN Max. Points: 20 Points

Instructions:
 All question should be answered in the same file using black font color.
 Upload your solution only on LMS.

STUDENT INFORMATION
Enrolment# Student Name
02-131202-052 Aneesha

Question-1:
By using examples write down the difference between if-else-statement and switch-statement.

Note: Write snippets of the C# code where necessary. Do not attach any VS Project with this document.
DIFFERENCE BETWEEN IF ELSE AND SWITCH STATEMENT
WITH THE HELP OF EXAMPLES:-

IF ELSE STATEMENT:-

Which statement will be executed depend upon the output of the expression inside
if Statement.

INPUT:-
if (35 > 20)
{
Console.WriteLine("35 is greater than 20");
}

else
Console.WriteLine("35 is less than 20");

OUTPUT:-
SWITCH STATEMENT:-
Which statement will be executed is decided by user.

INPUT:-

static void Main(string[] args)


{
int month = 3;
switch (month)
{
case1:
Console.WriteLine("January");
break;
case2:
Console.WriteLine("February");
break;
case3:
Console.WriteLine("March");
break;
case4:
Console.WriteLine("April");
break;
case 5:
Console.WriteLine("May");
break;
case 6:
Console.WriteLine("June");
break;
case 7:
Console.WriteLine("July");
break;

OUTPUT:-
(02)

IF ELSE STATEMENT:-

If-else statement uses multiple statement for multiple choices.

INPUT:-

{
int time = 15;
if (time < 8)
{
Console.WriteLine("Good morning.");
}
else if (time < 8)
{
Console.WriteLine("Good day.");
}
else
{
Console.WriteLine("Good evening.");
}
OUTPUT:
SWITCH STATEMENT:-

Switch statement uses single expression for multiple choices.

INPUT:-

int day = 1;
switch (day)
{
case 1:
Console.WriteLine("Today is Monday .");
break;
case 5:
Console.WriteLine("Today is Friday.");
break;
default:
Console.WriteLine("Looking forward to the Weekend.");
break;

OUTPUT:-

You might also like