@ -0,0 +1,27 @@ | |||||
#include <stdio.h> | |||||
int main (void) { | |||||
int number; | |||||
int i; | |||||
printf("Give a number: "); | |||||
if (scanf("%d", &number) != 1) { | |||||
printf("Not a number!\n"); | |||||
return 1; | |||||
} | |||||
i = number; | |||||
while (i <= number + 10) { | |||||
printf("%d ", i++); | |||||
} | |||||
printf("\n"); | |||||
return 0; | |||||
} |
@ -0,0 +1,39 @@ | |||||
#include <stdio.h> | |||||
#define DAYS_PER_WEEK 7 | |||||
unsigned getDays(void); | |||||
int main (void) { | |||||
int days; | |||||
days = getDays(); | |||||
while (days != 0) { | |||||
printf("%d days are %d weeks, %d days\n", days, days / DAYS_PER_WEEK, days % DAYS_PER_WEEK); | |||||
days = getDays(); | |||||
} | |||||
return 0; | |||||
} | |||||
unsigned getDays(void) { | |||||
int days; | |||||
printf("Number of days (<=0 to quit): "); | |||||
if (scanf("%d", &days) != 1 || days <= 0) { | |||||
days = 0; | |||||
} | |||||
return days; | |||||
} |
@ -0,0 +1,44 @@ | |||||
#include <stdio.h> | |||||
#include <float.h> | |||||
#define CM_PER_FEET 30.48 | |||||
#define CM_PER_INCH 2.54 | |||||
double getHeight(void); | |||||
int main (void) { | |||||
double height; | |||||
height = getHeight(); | |||||
while (height != 0) { | |||||
unsigned feet = height / CM_PER_FEET; | |||||
double inch = (height - feet * CM_PER_FEET) / CM_PER_INCH; | |||||
printf("%.2f cm = %u feet, %.1f inches\n", height, feet, inch); | |||||
height = getHeight(); | |||||
} | |||||
printf("bye\n"); | |||||
return 0; | |||||
} | |||||
double getHeight(void) { | |||||
double height; | |||||
printf("Enter a height in centimeters (<=0 to quit): "); | |||||
if (scanf("%lf", &height) != 1 || height <= 0) { | |||||
height = 0; | |||||
} | |||||
return height; | |||||
} |