Browse Source

Add first prog. exercise of chapter 05

master
T. Meissner 9 years ago
parent
commit
259690fc2e
3 changed files with 49 additions and 0 deletions
  1. BIN
      c_primer_plus/chapter05/01
  2. +39
    -0
      c_primer_plus/chapter05/01.c
  3. +10
    -0
      c_primer_plus/chapter05/Makefile

BIN
c_primer_plus/chapter05/01 View File


+ 39
- 0
c_primer_plus/chapter05/01.c View File

@ -0,0 +1,39 @@
#include <stdio.h>
#define MIN_PER_HOUR 60
unsigned getMinutes(void);
int main (void) {
unsigned min;
min = getMinutes();
while (min != 0) {
printf("%u minutes are %u:%02u HH:MM\n", min, min/MIN_PER_HOUR, min % MIN_PER_HOUR);
min = getMinutes();
}
return 0;
}
unsigned getMinutes(void) {
unsigned min;
printf("Time in minutes (0 to quit): ");
if (scanf("%u", &min) != 1) {
min = 0;
}
return min;
}

+ 10
- 0
c_primer_plus/chapter05/Makefile View File

@ -0,0 +1,10 @@
SRC := $(shell ls *.c)
%: %.c
gcc -Wall -Wextra $@.c -o $@
.PHONY: clean
clean:
@rm -f ??

Loading…
Cancel
Save