small code builds for .net
In this lab, you will learn how to use the if-else double-selection statement.
Perform the following tasks in the C# block:
- Declare a static public and character function grade with the parameter as marks having the datatype as integer.
- Declare a character variable grd.
- Use an
ifcondition to check if the marks obtained are greater than 89 and less than 101, then return the variable grd as A. - Use the
else ifcondition to check if the marks obtained are greater than 59 and less than 90, then return the variable grd as B. - Use the
elsecondition to return the variable grd as C, if marks obtained are less than 59. - Return the value of the variable grd using the
returnkeyword.
Note: In the C# block, replace the comments with the appropriate code, if required.
Sample input:
93
Sample output:
A
QUESTION 2
In this lab, you will learn how to use the switch multiple-selection statement.
Complete the given code in the C# block by performing the following tasks:
- Check the condition of the entered value and redirect it to the specific case.
- For cases '+', '-', '*', and '/', add, subtract, multiply, and divide the variables a and b, respectively, store the result in the variable result, and take the control outside the switch block using the
breakstatement.
Note: In the C# block, replace the comments with the appropriate code, if required.
Sample input:
8
8
*
Sample output:
64
QUESTION 3
In this lab, you will learn how to use the while loop.
Complete the given code in the C# block by performing the following tasks:
- Declare an integer variable count and set its initial value as 0.
- Declare a
whileloop with the test condition as n > 0. - Increment the value of the variable count by adding the variable n to it.
- Decrement the value of the variable n by 1.
- Return the final value of the variable count as the returning value of the function after the control comes out of the iteration statement.
Note: In the C# block, replace the comments with the appropriate code, if required.
Sample input:
12
Sample output:
78
QUESTION 4
In this lab, you will learn how to use the do-while loop.
Complete the given code in the C# block by performing the following tasks:
- Declare and initialize the value of the variables result and i as 1.
- Declare a
do-whileloop to store the product of the variables i and result in the variable result within the loop. - Increment the value of the variable i by 1, each time the loop executes.
- Add a test condition for the
do-whileloop in such a way that the loop executes till the value of the variable i becomes greater than a. - Return the calculated value of the variable result using the
returnkeyword.
Note: In the C# block, replace the comments with the appropriate code, if required.
Sample input:
5
Sample output:
120
QUESTION 5
In this lab, you will learn how to use the for loop.
Complete the given code in the C# block by performing the following tasks:
- Declare and initialize the variable fact as 1.
- Declare a
forloop with an initial value of the variable i as 1, test condition as i <= a, and increment value of the variable i by 1. - Calculate the product of the variables i and fact, and store it in the variable fact.
- Return the calculated factorial stored in the variable fact using the
returnkeyword.
Note: In the C# block, replace the comments with the appropriate code, if required.
Sample input:
5
Sample output:
120
QUESTION 6
In this lab, you will learn how to use the for loop.
Complete the given code in the C# block by performing the following tasks:
- Assign the Boolean value true to the variable prime using the bool function.
- Use the
ifcondition to check whether (a==1) returns false or (a==2) returns true. - Initialize the
forloop with the variable i whose initial value is 2 and execute the loop until the value of the variable i becomes less than or equal to a/2. - Use the
ifcondition to check whether the variable a returns 0 when it is divided by i. - If the above condition is true and the remainder of a/i is zero, then set the value of the Boolean variable prime as false.
- Set the variable prime as the returning value of the function.
Note: In the C# block, replace the comments with the appropriate code, if required.
Sample input:
97
Sample output:
True
QUESTION 7
In this lab, you will learn the concept of functions and work with them.
Complete the given code in the C# block by performing the following tasks:
- Declare a static public and integer function Average with five parameters as a, b, c, d, and e having the datatype as float.
- Calculate the average of the five variables and save it in the integer variable avg.
- Set the variable avg as the returning value of the function Average.
Note: In the C# block, replace the comments with the appropriate code, if required.
Sample input:
10
20
30
40
50
Sample output:
30
QUESTION 8
In this lab, you will learn the concept of functions and work with them.
Complete the given code in the C# block by performing the following tasks:
- Declare a static and non-returning value function using the
voidkeyword with the name Add and two integer parameters as x and y. - Declare an integer variable sum and store the sum of the variables x and y in the variable sum.
- Use
Console.WriteLine()to display the value of the variable sum.
Note: In the C# block, replace the comments with the appropriate code, if required.
Sample input:
10
20
Sample output:
306 years ago 10
Purchase the answer to view it
- file.net.docx
- epidemiolgy assignement
- ops571 w4 dq
- Critical Thinking essay (Instruction is uploaded)
- What makes it difficult to study the genes of prokaryotes and properly classify them?
- psy 345 week 5 Perception of Pleasure and Pain Presentation
- JAVA & Android
- paper
- finished
- Technology and Social Change
- MMIS 630: Database Systems