0% found this document useful (0 votes)
90 views5 pages

CP Assignment

The document provides instructions for an assignment on the differences between if-else statements and switch statements in C# code. It includes examples of: 1) An if-else statement that checks if 35 is greater than 20 and prints the result. 2) A switch statement that prints the month name based on the month number input. 3) An if-else if-else statement that prints a greeting based on the time, and a switch statement that prints the day of the week based on the number input.

Uploaded by

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

CP Assignment

The document provides instructions for an assignment on the differences between if-else statements and switch statements in C# code. It includes examples of: 1) An if-else statement that checks if 35 is greater than 20 and prints the result. 2) A switch statement that prints the month name based on the month number input. 3) An if-else if-else statement that prints a greeting based on the time, and a switch statement that prints the day of the week based on the number input.

Uploaded by

MSSM Engineering
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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