CS计算机代考程序代写 algorithm Faculty of Natural Sciences Eric Chen

Faculty of Natural Sciences Eric Chen
Goal
Tutorial 2 is a preparation for the lab 1.
The goal of this tutorial is to provide practices on algorithm development and program development process in C.
Please read the lab1 instruction before you come to Tutorial 2.
Formatted Output
In Task 1 and Task 2 of Lab 1, you need to have a well formatted output. How to generate such a format in C?
The output function is printf(). You can use the width in the printf( ) conversion specifier to give desired the width for each printing item.
To do:
try the following printf( ) examples: int a = 100;
float f = 1.2345;
printf(“\t%6d %6d %6d\n “, a, 2*a, 10*a); printf(“\tf=%.6\n “, f);
Bit Operations
Task 3 in Lab 1 needs bit level operations.
Here we can consider the input question in Task 3 of Lab 1. Suppose that we want to enter an integer with a value (in binary) as follows:
Binary: 0000 0000 0001 1010 corresponding decimal: 26
We can enter 1 3 4 -1
Where the positions with binary 1 in the integer are entered, and the computer can generate a number of value 26.
To do:
Develop an algorithm to do this input.
Polya’s Problem-Solving Method
We apply 4 steps to solve a problem in C programming: (1) Understand the problem.
You should spend enough time on studying the problem to understand what is, before you move on to the next step.
In this step, you should produce:
Page 1 of 2 2019-04-24

Page 2 of 2 2019-04-24
In this step, you should develop an algorithm for the problem. Techniques such as top-down design can be applied. The results of this step are
 Flowchart representation
 Pseudo-code representation
(3) Implementation in C
In this step, you translate the algorithm develop into the implementation in C. If your algorithm representations are clear and simple, the implementation is quick and simple. The result of this step consists of the C source files.
(4) Test and Analysis
In this step, you should test your program with the test cases developed in Step 1 and check if the results are correct. If not, you need to analyse what is wrong and correct the errors. Debugging techniques can applied in this step. In Lecture 11, we will introduce the debugging techniques.
To do on Task 1 Multiplication Table, Task 2 Computation of ex in lab 1:
(1) Complete step 1 individually
(2) Discuss your understanding with your classmates
(3) Algorithm development individually
(4) Discuss your algorithms with your classmates, if you like. Remember that you should not copy-and-paste.
 a problem statement,
 the input, and expected output
 the test cases: a set of input representatives and their output
(2) Algorithm development
Kristianstad University, Sweden | +46 44 250 30 00 | www.hkr.se/en