Lab Sheet For Week 2 and 3
Lab Sheet For Week 2 and 3
For each of the data item given below, choose an appropriate data type and write a C#
1
statement to declare the variable
• Variable myAge to store your own age
• Variable income to keep track of Arun’s personal income
• Variable temp_c to store temperature in degree Celsius
• Variable temp_k to store temperature in Kelvin
• Variable name to store Aum’s full name
Ans.
int myAge;
double income;
double temp_c;
double temp_k;
string name;
. Let x, y and z be of type int and ch of type char. Describe the condition that makes each of
2
the following Boolean expressions true
Ans.
.
1 > 2: True when x is greater than 2.
x
2. x % 2 == 0: True when x is an even number.
3. (x % 5 == 0): True when x is divisible by 5.
4. (x % y == 0): True when x is divisible by y.
5. ((x % y == 0) && (z % y == 0)): True when both x and z are divisible by y.
6. ch == 'a': True when ch is equal to the character 'a'.
7. ((ch >= 'a') && (ch <= 'z')): True when ch is a lowercase letter.
8. ((ch >= 'A') && (ch <= 'Z')): True when ch is an uppercase letter.
9. ((ch >= '0') && (ch <= '9')): True if ch is a character between '0' and '9'.
0.(ch != '*'): True when ch is not equal to '*'.
1
11.!(ch == '*'): True when ch is not equal to '*'.
. Run the code snippet given below and fill the answers of the question using System ; class
3
Test { static void Main () { double x = 3.0 , y = 2.0; int a = 10 , b = 2; -------------------------(fill this
line with code to be executed mentioned below) Console.ReadLine (); } } Console.WriteLine(a);
--------- 10 Console.WriteLine(x+a); Console.WriteLine(a/b); Console.WriteLine(y/x);
Console.WriteLine(y%x); Console.WriteLine((a+b)/b%a); Console.WriteLine(9.0/5.0*(a-x));
Console.WriteLine(x+y-x*y%x); Console.WriteLine(57%50/25);
Ans.
using System;
class Lab1 {
static void Main() {
double x = 3.0, y = 2.0;
int a = 10, b = 2;
onsole.WriteLine(a);
C // Output: 10
Console.WriteLine(x + a); // Output: 13
Console.WriteLine(a / b); // Output: 5
Console.WriteLine(y / x); // Output: 0.6666666666666666
Console.WriteLine(y % x); // Output: 2
Console.WriteLine((a + b) / b % a); // Output: 1
Console.WriteLine(9.0 / 5.0 * (a - x)); // Output: -9.0
Console.WriteLine(x + y - x * y % x); // Output: 6
Console.WriteLine(57 % 50 / 25); // Output: 0
Console.ReadLine();
}
}
Ans.
using System;
class NumberCheck {
static void Main() {
if (number % 2 == 0) {
Console.WriteLine($"{number} is even.");
} else {
Console.WriteLine($"{number} is odd.");
}
if (number % 6 == 0) {
Console.WriteLine($"{number} is a multiple of 6.");
} else {
Console.WriteLine($"{number} is not a multiple of 6.");
}
. Write a C# program which attempts to identify the quadrant of the input (x, y) coordinates. If
5
the input coordinates happen to be on either X-axis or Y-axis, the program will display “I don’t
know.” Sample Output Please input X: -50 Please input Y: 10 (-50, 10) is in Q2 To take the user
input int i = int.Parse(Console.ReadLine()); // reading an integer data float f =
float.Parse(Console.ReadLine());// reading a floating point data
Ans.
using System;
amespace QuadrantIdentifier
n
{
class Program
{
static void Main(string[] args)
{
int x, y;
Ans.
using System;
class AirTimeFeeCalculator {
static void Main() {
int airTimeFee;
. Write a BMI calculator program which will find your body status. Use the following rule
7
BMI = Weight(in kg)/ height*height (in meter)
ample output
S
Enter your weight: 65
Enter your height: 1.75
Your BMI is 21.22.
You are normal.
Ans.
using System;
lass BMICalculator
c
{
static void Main(string[] args)
{
double weight, height, bmi;
. Write a C# program to determine whether the input number is an integer. (Hint: Use the
8
method Math.Round())
Ans.
using System;
class IntegerCheck {
static void Main() {
ample Output
S
Please input a letter: A
The corresponding number of A is 2.
Please input a letter: *
There is no corresponding number for *.
Ans.
using System;
lass LetterToNumberTranslator
c
{
static void Main(string[] args)
{
char letter;
witch (letter)
s
{
case 'A':
case 'B':
case 'C':
Console.WriteLine("The corresponding number is 2.");
break;
case 'D':
case 'E':
case 'F':
Console.WriteLine("The corresponding number is 3.");
break;
case 'G':
case 'H':
case 'I':
Console.WriteLine("The corresponding number is 4.");
break;
case 'J':
case 'K':
case 'L':
Console.WriteLine("The corresponding number is 5.");
break;
case 'M':
case 'N':
case 'O':
Console.WriteLine("The corresponding number is 6.");
break;
case 'P':
case 'Q':
case 'R':
case 'S':
Console.WriteLine("The corresponding number is 7.");
break;
case 'T':
case 'U':
case 'V':
Console.WriteLine("The corresponding number is 8.");
break;
ase 'W':
c
case 'X':
case 'Y':
case 'Z':
Console.WriteLine("The corresponding number is 9.");
break;
default:
Console.WriteLine("There is no corresponding number for {0}.", letter);
break;
}
}
}
Q10.
Ans.
using System;
lass BookShippingCostCalculator
c
{
static void Main(string[] args)
{
string shippingType;
double weightInGrams, cost;
Console.WriteLine("The shipping cost is {0} rupees and {1} paise.", rupees, paise);
}