Commit fe2f2f3fa645cb030f0b6d8c012f94dc79af2db2
1 parent
acf223478c
Exists in
master
HW4 Finished
Showing 8 changed files with 125 additions and 0 deletions Inline Diff
HW4/compress.c
View file @
fe2f2f3
File was created | 1 | #include <stdio.h> | ||
2 | //This program gets a string from the user, removes the space characters as | |||
3 | // well as vowels and prints the compressed string. | |||
4 | ||||
5 | int main() { | |||
6 | ||||
7 | char current; | |||
8 | ||||
9 | printf("String: "); | |||
10 | while ((current=getchar()) != '\n') { | |||
11 | if (current!='a' && current!='e' && current!='i' | |||
12 | && current!='o' && current!= 'u' | |||
13 | && current!= ' ' && current != '\t') | |||
14 | putchar(current); | |||
15 | } |
HW4/compress.sol
View file @
fe2f2f3
HW4/guess.c
View file @
fe2f2f3
File was created | 1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | |||
3 | #include <time.h> | |||
4 | ||||
5 | int main(){ | |||
6 | ||||
7 | srand(time(NULL)); | |||
8 | int target = rand() % 20 + 1; | |||
9 | int guess, number_ties=0; | |||
10 | printf("Guess my number: "); | |||
11 | target = 14; | |||
12 | do { | |||
13 | scanf("%d", &guess); | |||
14 | number_ties++; | |||
15 | ||||
16 | if (guess < target-4) | |||
17 | printf("Your guess is too low, guess again: "); | |||
18 | else if (guess < target) | |||
19 | printf("Your guess is low, guess again: "); | |||
20 | else if (guess > target+4) | |||
21 | printf("Your guess is too high, guess again: "); | |||
22 | else if (guess > target) | |||
23 | printf("Your guess is high, guess again: "); | |||
24 | } while (guess != target); | |||
25 |
HW4/guess.sol
View file @
fe2f2f3
HW4/tennis.c
View file @
fe2f2f3
File was created | 1 | #include <stdio.h> | ||
2 | //This program gets the score of a tennis match and announce it as in | |||
3 | //the commentaries, e.g. 40-30 is forty thirty, and 40-40 is deuce, 15-0 is | |||
4 | // fifteen love. | |||
5 | ||||
6 | int main(){ | |||
7 | ||||
8 | int score1, score2; | |||
9 | printf("Result: "); | |||
10 | scanf("%d-%d", &score1, &score2); | |||
11 | ||||
12 | if (score1 == score2){ | |||
13 | switch (score1) { | |||
14 | case 0 : | |||
15 | printf("Announcement: love all\n"); | |||
16 | break; | |||
17 | case 1 : | |||
18 | printf("Announcement: fifteen all\n"); | |||
19 | break; | |||
20 | case 2 : | |||
21 | printf("Announcement: thirty all\n"); | |||
22 | break; | |||
23 | case 3 : | |||
24 | printf("Announcement: deuce\n"); | |||
25 | break; | |||
26 | } | |||
27 | } else { | |||
28 | switch (score1) { | |||
29 | case 0 : | |||
30 | printf("Announcement: love "); | |||
31 | break; | |||
32 | case 1 : | |||
33 | printf("Announcement: fifteen "); | |||
34 | break; | |||
35 | case 2 : | |||
36 | printf("Announcement: thirty "); | |||
37 | break; | |||
38 | case 3 : | |||
39 | printf("Announcement: forty "); | |||
40 | break; | |||
41 | } | |||
42 | switch (score2) { | |||
43 | case 0 : | |||
44 | printf("love\n"); | |||
45 | break; | |||
46 | case 1 : | |||
47 | printf("fifteen\n"); | |||
48 | break; | |||
49 | case 2 : | |||
50 | printf("thirty\n"); | |||
51 | break; | |||
52 | case 3 : | |||
53 | printf("forty\n"); | |||
54 | break; | |||
55 | } |
HW4/tennis.sol
View file @
fe2f2f3
HW4/triangle.c
View file @
fe2f2f3
File was created | 1 | #include <stdio.h> | ||
2 | //This program gets three double numbers from the user and | |||
3 | // declares whether we can have a triangle with these lengths or not. | |||
4 | ||||
5 | int main(){ | |||
6 | ||||
7 | double a, b, c; | |||
8 | printf("Three lengths: "); | |||
9 | scanf("%lf %lf %lf", &a, &b, &c); | |||
10 | ||||
11 | if (a+b<=c || a+c<=b || b+c<=a) | |||
12 | printf("Triangle is impossible!\n"); | |||
13 | else |
HW4/triangle.sol
View file @
fe2f2f3