Presentation is loading. Please wait.

Presentation is loading. Please wait.

Revision.

Similar presentations


Presentation on theme: "Revision."— Presentation transcript:

1 Revision

2 Your programs should generally..
Have plenty of comments Be uniform in style Have good structure Be simple, not bloated Be universal (cover corner cases) Be modular (easily reusable) Effective (optimal algorithms) Easily readable 2018 Risto Heinsar

3 Basic data types Data type Format Size Integers int %d 2 or 4 bytes
short %h 2 bytes unsigned %u Characters char %c 1 byte char[] %s ? byte(s) Floating point float %f 4 bytes double %lg 8 bytes 2018 Risto Heinsar

4 Loops while do while for
i = 0; while (i < 10) { printf("%d\n", i); i++; } i = 0; do { printf("%d\n", i); i++; } while ( i < 10); for (i = 0; i < 10; i++) { printf("%d\n", i); } 2018 Risto Heinsar

5 Functions and programm structure
#include <stdio.h> void PrintDigit(int value); // function prototype int main(void) //main() function with return type { int digit; scanf("%d", &digit); PrintDigit(digit); // function call return 0; // return value from main function } void PrintDigit(int value) printf("Number read was: %d\n", value); 2018 Risto Heinsar

6 Revision task 1 Initialize a string of Your choosing
Remove all of the vowels from that string. The resulting string must be written in a different variable, original must stay intact! Output both the original and the modified string on the screen. Create at least one function besides main in a meaningful way 2018 Risto Heinsar

7 Revision task 2 (use our code template)
The data is mixed type (both metric and imperial), stored in a single array. You can think of it as distance travelled by office workers during work hours in an international setting. One line per employee. The second column of the array defines the units – 0 for metric, 1 for imperial. Data units are either meters or feet. The output must be only given in metric units. Output the distance walked by every employee Output the following statistics: average distance walked, total distance walked Create at least three functions besides main in a meaningful way 1 foot = meters 2018 Risto Heinsar

8 Revision task 3 Read N digits in between 0 ≤ ai ≤ 9
Find the frequency for each of the digits (rate of occurrence) Output the digits with their frequencies E.g. Number 0 occurred 1 time Number 1 occurred 12 times … Number 9 occurred 9 times Output the basic statistics: Lowest and highest number entered, most common number(s) Create at least three functions besides main in a meaningful way, one of which must return a non-void value 2018 Risto Heinsar


Download ppt "Revision."

Similar presentations


Ads by Google