Primitive Data Types and Variables Homework
Primitive Data Types and Variables Homework
Variables
This document defines homework assignments from the C# Basics Course @ Software
University. Please submit as homework a single zip / rar / 7z archive holding the solutions
(source code only) of all below described problems.
Problem 3. Variable in
Hexadecimal Format
Declare an integer variable and assign it with the value 254 in hexadecimal format (0x##).
Use Windows Calculator to find its hexadecimal representation. Print the variable and ensure
that the result is 254.
Note that the symbol may be displayed incorrectly at the console so you may need to
change the console character encoding to UTF-8 and assign a Unicode-friendly font in the
console. Note also, that under old versions of Windows the symbol may still be displayed
incorrectly, regardless of how much effort you put to fix it.
First name
Last name
Age (0...100)
Gender (m or f)
Personal ID number (e.g. 8306112507)
Unique employee number (2756000027569999)
Declare the variables needed to keep the information for a single employee using appropriate
primitive data types. Use descriptive names. Print the data at the console.
Number
a
Number
b
Explanation
5.3
6.01
false
5.000000 5.000000
01
03
true
5.000000 5.000000
05
01
true
0.000000
0.000000
07
7
true
4.999999 4.999998
false
4.999999 4.999998
false
Exam Problems
All of the problems below are given from the previous C# Basics exams. You are not
obligated to submit any of them in your homework, but it is highly recommend that you
solve some or all of them so you can be well prepared for the upcoming exam. You may need
to learn how to use conditional statements, loops, arrays and other things (learn in internet
how or read those chapters in the book Fundamentals of computer programming with C#).
If you still find those problems too hard for solving its very useful to check and understand
Software University Foundation (softuni.org). This work is licensed under the
CC-BY-NC-SA license.
Page 3 of 9
Follow
us:
the solutions. You can download all solutions and tests for this variant here or check all
previous exams (scroll down to the bottom of the page). You can also test your solutions in
our automated judge system to see if you pass all tests.
Input
The input data should be read from the console. It consists of three input values, each at
separate line:
The string t for leap year or f for year that is not leap.
The number p number of holidays in the year (which are not Saturday or Sunday).
The number h number of weekends that Joro spends in his hometown.
The input data will always be valid and in the format described. There is no need to check it
explicitly.
Output
Constraints
Examples
Inpu
t
t
Outp
ut
38
Comments
52 weekends total in the year, split into:
1
2
Input
f
3
2
Outp
ut
36
Input
t
2
3
Outp
ut
39
Input
f
10
5
Outp
ut
41
Input
t
0
1
Outp
ut
38
Input
The input data should be read from the console.
The input data will always be valid and in the format described. There is no need to check it
explicitly.
Output
Constraints
Examples
Input
4
Output
Input
Yes, sum=5
Output
No, diff=1
Input
2
4
-1
-1
2
3
Output
No, diff=2
0
0
2
2
1
1
1
Input
The input data will always be valid and in the format described. There is no need to check it
explicitly.
Output
The output should be printed on the console.
You should print the sunglasses on the console. The sunglasses consist of three parts:
frames, lenses and a bridge (the connection between the two frames). Each frame's width
is double the height N and should be printed using the character '*' (asterisk). Print the lenses
with the character '/'. Finally, connect the two frames with a bridge that is of size N, using the
character '|'. Leave the rest of the space between the frames blank.
Constraints
Examples
Input
Output
Input
Output
****** ******
*////*|||*////*
****** ******
**********
**********
*////////*
*////////*
*////////*|||||*////////*
*////////*
*////////*
**********
**********
Input
The input data will always be valid and in the format described. There is no need to check it
explicitly.
Output
The output should be printed on the console. Print all nine-digit magic numbers matching
given difference diff and given sum of digits sum, in increasing order, each at a separate
line. In case no nine-digit magic numbers exits, print No.
Constraints
The number sum will be a positive integer number in the range [0100].
The number diff will be a positive integer number in the range [01000].
Allowed working time for your program: 0.25 seconds.
Allowed memory: 16 MB.
Examples
Inpu
t
27
46
Output
12517121
7
Comments
1+2+5+1+7+1+2+1+7 = 27; 171-125 = 46; 217-171 = 46
1+3+1+1+7+7+2+2+3 = 27; 177-131 = 46; 223-177 = 46
Software University Foundation (softuni.org). This work is licensed under the
CC-BY-NC-SA license.
Page 7 of 9
Follow
us:
13117722
3
22126731
3
Inpu
t
24
103
Output
12122432
7
21131441
7
Inpu
t
12
15
Output
No
Comments
1+2+1+2+2+4+3+2+7 = 24; 224-121 = 103; 327-224 = 103
2+1+1+3+1+4+4+1+7 = 24; 314-211 = 103; 417-314 = 103
Comments
No nine-digit magic numbers with sum=12 and diff=15
Input
The input data will always be valid and in the format described. There is no need to check it
explicitly.
Output
The output should be printed on the console. Print exactly n bytes, each at a separate line
and in range [0..255], obtained by applying the bit inversions over the input sequence.
Constraints
Examples
Inpu
t
Outpu
t
2
11
45
87
173
71
Inpu
t
Outpu
t
3
5
45
87
254
169
118
246
Comments
We have the following sequence of 16 bits (2 bytes):
00101101 01010111
We invert the bits 1 and 12 (step=11). We get:
10101101 01000111
Comments
We have the following sequence of 24 bits (3 bytes):
00101101 01010111 11111110
We invert the bits 1, 6, 11, 16 and 21 (step=5). We get:
10101001 01110110 11110110