Professional Documents
Culture Documents
CP Assignment
CP Assignment
CP Assignment
(Karachi Campus)
Department of Software Engineering
ASSIGNMENT#01 – Fall 2020
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:-
OUTPUT:-
(02)
IF ELSE STATEMENT:-
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:-
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:-