This commit is contained in:
unlockable
2022-09-30 16:16:36 +08:00
parent 2f39d88778
commit aedf18a247
4 changed files with 58 additions and 0 deletions

20
03/Exercise01.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdbool.h>
int main() {
int sLen, iLen, lLen, usLen, uiLen, ulLen, cLen, bLen, dLen, fLen;
sLen = sizeof(short);
iLen = sizeof(int);
lLen = sizeof(long);
usLen = sizeof(unsigned short);
uiLen = sizeof(unsigned int);
ulLen = sizeof(unsigned long);
cLen = sizeof(char);
bLen = sizeof(bool);
dLen = sizeof(double);
fLen = sizeof(float);
float fTestMaxLength =0.1234567890123456789;
printf("short: %d\nint: %d\nlong: %d\nunsigned short: %d \nunsigned int: %d\nunsigned long: %d\nchar: %d\nbool: %d\ndouble: %d\nfloat: %d\n", sLen, iLen, lLen, usLen, uiLen, ulLen, cLen, bLen, dLen, fLen);
printf("floatMaxLength: %f", fTestMaxLength);
return 0;
}

12
03/Exercise02.c Normal file
View File

@@ -0,0 +1,12 @@
#include <stdio.h>
int main() {
int a = 0, b = 0;
scanf("%d %d", &a, &b);
printf("%c%c%c%c%c\n", b, b, a, b, b);
printf("%c%c%c%c%c\n", b, a, b, a, b);
printf("%c%c%c%c%c\n", a, b, b, b, a);
printf("%c%c%c%c%c\n", b, a, b, a, b);
printf("%c%c%c%c%c\n", b, b, a, b, b);
return 0;
}

17
03/Exercise03.c Normal file
View File

@@ -0,0 +1,17 @@
#include <stdio.h>
int nextMonth(int currentMonth, int lastMonthAdult, int lastMonthChild) {
if (currentMonth == 7) {
return lastMonthAdult + lastMonthChild;
}
else {
return nextMonth(currentMonth + 1, lastMonthAdult + lastMonthChild, lastMonthAdult);
}
}
int main() {
int sheepCount = 0;
sheepCount = nextMonth(1,0,2);
printf("Number of sheep: %d\nValue: %d", sheepCount, sheepCount*10);
return 0;
}

9
03/Optional.c Normal file
View File

@@ -0,0 +1,9 @@
#include <stdio.h>
int main() {
char number[12];
printf("Your phone number is?\n");
scanf("%s", number);
printf("Your phone number is %s", number);
return 0;
}