UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | lectures | news | help

countdown

Program

/* File: countdown.c * * A very simple recursive function. */ #include <stdio.h> void Countdown (int) ; main() { int n ; printf("Engaging the auto-destruct sequence\n") ; printf("Enter number of seconds to auto-destruct: ") ; scanf("%d", &n) ; printf("Counting down from %d\n", n) ; Countdown(n) ; } /* This is a simple recursive function */ void Countdown (int k) { if (k == 0) { printf("KABOOM!!!\n") ; } else { printf(" %d seconds to auto-destruct\n", k) ; Countdown (k - 1) ; } }

Output

lassie% cc201 countdown.c lassie% lassie% a.out Engaging the auto-destruct sequence Enter number of seconds to auto-destruct: 9 Counting down from 9 9 seconds to auto-destruct 8 seconds to auto-destruct 7 seconds to auto-destruct 6 seconds to auto-destruct 5 seconds to auto-destruct 4 seconds to auto-destruct 3 seconds to auto-destruct 2 seconds to auto-destruct 1 seconds to auto-destruct KABOOM!!! lassie% lassie% a.out Engaging the auto-destruct sequence Enter number of seconds to auto-destruct: 17 Counting down from 17 17 seconds to auto-destruct 16 seconds to auto-destruct 15 seconds to auto-destruct 14 seconds to auto-destruct 13 seconds to auto-destruct 12 seconds to auto-destruct 11 seconds to auto-destruct 10 seconds to auto-destruct 9 seconds to auto-destruct 8 seconds to auto-destruct 7 seconds to auto-destruct 6 seconds to auto-destruct 5 seconds to auto-destruct 4 seconds to auto-destruct 3 seconds to auto-destruct 2 seconds to auto-destruct 1 seconds to auto-destruct KABOOM!!! lassie%


CSEE | 201 | 201 F'98 | lectures | news | help

Sunday, 06-Dec-1998 18:04:11 EST