Your tutor has asked a lab pair to present their week 3 work.
Discuss the good, the bad and the ugly aspects of their code.
Please be gentle in any criticism - we are all learning!
Your tutor will facilitate the formation of new pairs.
Please cooperate with them.
What sort of problems can be caused by using uninitialised variables in programs?
Why do programs with uninitialised variables apparently work?
#include <stdio.h> int main(void) { int number; int row, column; // Obtain input printf("Enter size: "); scanf("%d", &number); row = 1; while (row <= number) { column = 1; while (column <= number) { printf("*"); column = column + 1; } printf("\n"); row = row + 1; } return 0; }The output if the user types in the number 5 is:
./square Enter size: 5 ***** ***** ***** ***** *****Modify the program so that it prints out a triangle like this:
./triangle Enter number: 5 ----* ---** --*** -**** *****
Now modify so it prints the following pattern:
./diagonal Enter an integer: 10 *--------- -*-------- --*------- ---*------ ----*----- -----*---- ------*--- -------*-- --------*- ---------*Now modify so it prints the following pattern:
./bars Enter an integer: 9 -*-*-*-*- -*-*-*-*- -*-*-*-*- -*-*-*-*- -*-*-*-*- -*-*-*-*- -*-*-*-*- -*-*-*-*- -*-*-*-*-
log10.c
which reads a positive integer, and calculates the integer part
of its base 10 logarithm without using functions from the maths library.
Hint: repeatedly divide by 10.
Your tutor may still choose to cover some of the questions time permitting.
./rectangle Enter rectangle height and length: 3 5 ***** * * *****
./diamond Enter side length: 3 * * * * * * * * ./diamond Enter side length: 6 * * * * * * * * * * * * * * * * * * * *
./readInts Please enter some integers: 10 -90 100 999 78hello You entered 5 integers ./readInts Please enter some integers: 1 2 3 4 5 6 7 8 9 10 11 12 hello You entered 12 integers
./multiplication_table Enter multiplication table size: 5 1| 1 2 3 4 5 2| 2 4 6 8 10 3| 3 6 9 12 15 4| 4 8 12 16 20 5| 5 10 15 20 25
./guess_number Random number is between 1 and 100. Enter your guess: 50 Random number is between 1 and 50. Enter your guess: 40 Random number is between 1 and 40. Enter your guess: 37 Yay, you guessed the number 37 correctly! ./guess_number Random number is between 1 and 100. Enter your guess: 80 Random number is between 80 and 100. Enter your guess: 90 Random number is between 80 and 90. Enter your guess: 85 Random number is between 80 and 85. Enter your guess: 83 Random number is between 80 and 83. Enter your guess: 82 Yay, you guessed the number 82 correctly!