Вы находитесь на странице: 1из 7

Muhammad Muaaz

02-134201-052
Lab Tasks#6
1. Create a simple program to check whether the no is even or odd.
Source Code
Console.WriteLine("------Task 1-------");
char C;
//char C= a;
//C = Convert.ToChar(Console.ReadLine());
Console.Write("C = ");
C = Convert.ToChar(Console.ReadLine());
switch (C)
{
case 'a':
Console.WriteLine("Your alphabet is Vowel");
Console.WriteLine("----------Vowel---------");
break;
case 'e':
Console.WriteLine("Your alphabet is Vowel");
Console.WriteLine("----------Vowel---------");
break;

case 'i':
Console.WriteLine("Your alphabet is Vowel");
Console.WriteLine("----------Vowel---------");
break;
case 'o':
Console.WriteLine("Your alphabet is Vowel");
Console.WriteLine("----------Vowel---------");
break;
case 'u':
Console.WriteLine("Vowel");
break;

}
Console.WriteLine("---------------------------");

}
Output
2. Create a simple calculator using if else condition in which you will take two number as
input and ask user which operation he/she wants to perform.
Source Code
Console.WriteLine("------Task 2-------");
Console.WriteLine(" Calculator ");
Double a, b, Calculator;
Console.WriteLine("Enter first number");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter second number");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter your choice");

Calculator = Convert.ToInt32(Console.ReadLine());

if (Calculator == 1)

{
Console.WriteLine("--------- Addition -------");
Calculator = a + b;
Console.WriteLine(a + "+" + b + "=" + Calculator);
}

else if (Calculator == 2)

{
Console.WriteLine("--------- Subtraction -------");
Calculator = a - b;
Console.WriteLine(a + "-" + b + "=" + Calculator);
}

else if (Calculator == 3)

{
Console.WriteLine("--------- Multiplication -------");
Calculator = a / b;
Console.WriteLine(a + "/" + b + "=" + Calculator);
}

else if (Calculator == 4)

{
Console.WriteLine("--------- Divison -------");
Calculator = a / b;
Console.WriteLine("\t " + a + "/" + b + "=" + Calculator);
}
else if (Calculator == 5)

{
Console.WriteLine("--------- Modulus -------");
Calculator = a % b;
Console.WriteLine(a + "%" + b + "=" + Calculator);
}

else
{

Console.WriteLine("YOUR OPERATION IS INVALID");


}

Output

3. Write a Program using nested ifs in which the user is asked to do the following:
a. Confirm if user wants to play the game “Guess the secret number”
b. If false, then print message “Maybe next time”; if true, then ask “Enter your age”
c. If age is less than 5 then print “You are too young to play”, else ask “Enter any
number”.
d. If number is equal to the secret number then print “You have successfully guessed
the secret number; else print “You were not successful in guessing the secret
number”.
Note: You have to store a secret number in a variable in order to compare it.
Source Code
Console.WriteLine("----------- Task#3 -------------");

String c = "Intelligent", y = "You";


if (y == c)
{
Console.WriteLine("Are you Sure You are Intelligent?");
}

else
{
Console.WriteLine("");
}
Console.WriteLine("Yes Or No");
char yo = 'y', n = 'n';
char Y = Convert.ToChar(Console.ReadLine());
if (Y == yo)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
Console.WriteLine("-------------------");
Console.WriteLine(" lets Play the Game ");
Console.WriteLine("Guess the Secret Number ");
Console.Write("WHAT IS YOUR AGE: ");

int s;
int age;

age = Convert.ToInt32(Console.ReadLine());

if (age >= 5)
{
Console.WriteLine("Play the Game");

}
else
{
Console.WriteLine("You are too young to play");
}
Console.Write("Enter any Number: ");
s = Convert.ToInt32(Console.ReadLine());
int a = 2;
if (s == a)
{
Console.WriteLine("You! Guess The Right..");
Console.WriteLine("You have successfully guessed the secret number ");
}
else
{
Console.WriteLine(" May be next time");
}

Output

4. Create simple application which will check the vowel using switch case
Source Code
{
Console.WriteLine(" ------Task 4 -------");
int num, S;

Console.WriteLine("Check whether a number is even or odd ");

Console.Write ("Integer : ");


num = Convert.ToInt32(Console.ReadLine());
S = num / 2;
if (num % 2 == 0)
Console.WriteLine("{0} Even .", num);

else
Console.WriteLine("{0} Odd .", num);
Console.WriteLine("---------------------------");
}

Output

Вам также может понравиться