Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

LO 3, 5 Program Quiz (60 Marks)

1. Write a C# program to determine the day of the week 10 days after the current date.
Expected Output :

Today: Monday
The day of the week 10 days after today: Thursday

2. Write a program in C# to create a function for the sum of two numbers and reuse by
calling it from main method.
Expected Output :
Function to calculate the sum of two numbers:
--------------------------------------------------
Enter the first number: 2
Enter the second number: 5
The sum of these two numbers: 7

3. Write a program in C# to create a function to input a string and count the number of
spaces within the string.
Expected Output :
Function to count number of spaces in a string:
----------------------------------------------------
Please input a string: There are ITPEC_2022 Intakes.
" There are ITPEC_2022 Intakes. " contains 3 spaces

1
4. Write a program in C# Sharp to calculate the sum of elements in an array.
Expected Output:

Function: Calculate the sum of the elements in an array:


---------------------------------------------------------------------------
Input 5 elements in the array:
element - 0 : 1
element - 1 : 2
element - 2 : 3
element - 3 : 4
element - 4 : 5
The sum of the elements of the array is 15

5. Write a C# program to create a function to swap two integer numbers.


Expected Output:

Function: To swap the values of two integer numbers:


----------------------------------------------------------
Enter the 1st number: 45
Enter the 2nd number: 65

After swapping,
The 1st number: 65
The 2nd number: 45

2
6. Write a C# program to create a function to display the n number Fibonacci sequence.
Expected Output:
Function: To display the n number Fibonacci series:
------------------------------------------------------------
Input number of Fibonacci Series : 10
The Fibonacci series of 10 numbers is :
0 1 1 2 3 5 8 13 21 34

7. Write a C# program to compute the sum of two given integers.


If two values are the same, return the triple of their sum. Otherwise, return their
differences value.
Expected Output:
Enter First value : 2
Enter Second value : 2
Output: (2+2)*3 = 12
(or)
Enter First value : 3
Enter Second value :2
Output: (3-2) = 1

8. Write a C# program to check whether the given integer must be between 20 and 100.
Expected Output:
Input an integer: 15
False
Input an integer: 80
True

3
9. Write a C# program to print odd numbers from 1 to 99 as console output. Prints one
number per line. The sample output as follows:
Expected Output:
Odd numbers from 1 to 99. Prints one number per line.
1
3
5
7
9
...
95
97
99

10. Write a C# program to compute the total sum of each integer's digit value.
Expected Output:
Input a number (only integer): 12
The total sum of each integer's digit value: 3

11. Write a C# program to reverse the words of a sentence without using Reverse ()
Method.
Expected Output:
Original String: Order reversed
Reverse String: reversed Order

4
12. Write a C# program to find the largest and lowest values from three integer values.
Expected Output:
Input first integer : 1
Input second integer: 2
Input third integer : 3

Largest of three : 3
Lowest of three : 1

13. Write a C# program to create a string where the first 4 characters are in lower case.
If the string is less than 4 characters, make the whole string in upper case. Otherwise,
make the whole string in lower case.
Expected Output:

Input a string : javaProgramming


Output a string as : javaprogramming

(or)
Input a string : web
Output a string as : WEB
(or)
Input a string : itpec
Output a string as : itpec

5
14. Write a C# Sharp program to read 10 numbers and find their average and sum.
Expected Output:
Read 10 numbers and calculate sum and average:
-----------------------------------------------------------------
Input the 10 numbers:
Number-1 :2
Number-2 :4
Number-3 :6
Number-4 :8
Number-5 :10
Number-6 :12
Number-7 :14
Number-8 :16
Number-9 :18
Number-10 :20
The sum of 10 numbers is: 110
The Average is: 11

15. Write a program in C# Sharp to display a right-angle triangle with an asterisk.


The pattern like:
*
**
***
****

6
Expected Output:
Display the pattern like right-angle using asterisk:
-----------------------------------------------------------------
Input number of rows: 10
*
**
***
****
*****
******
*******
********
*********
**********

16. Write a program in C# Sharp to display a pattern like a right-angle triangle with a
number.
The pattern like:
1
12
123
1234

7
Expected Output:
Display the pattern as right-angle triangle using number:
--------------------------------------------------------------------------
Input number of rows: 5
1
12
123
1234
12345

17. Write a C# Sharp program to display an alphabet pattern like P with an asterisk.
Expected Output:
Display the pattern like 'P' with an asterisk:
---------------------------------------------------------
****
* *
* *
****
*
*
*

8
18. Write a C Sharp program to display an alphabet pattern like ‘Z’ with an asterisk.
Expected Output:
Display the pattern like 'Z' with an asterisk:
--------------------------------------------------------
*******
*
*
*
*
*
*******

19. Write a C# program to output the name and age attributes of the Student class with
data hiding (encapsulation) feature and the sample output in console as follows:
Expected Output:
Sample Output:
Name: James
Age: 21

9
20. Create a C# program that represents the following UML class diagram. The diagram
represents public, private, and protected attributes as well as class dependency and
inheritance.

--------------------------------------------------The END------------------------------------------------------

10

You might also like