12课练习2 3

This commit is contained in:
unlockable
2022-12-05 19:36:17 +08:00
parent 2373f1f8e6
commit ad1f59c0ec
2 changed files with 64 additions and 0 deletions

25
12/Exercise02.c Normal file
View File

@@ -0,0 +1,25 @@
#include <stdio.h>
int main() {
int A[10][10] = {
{0,1,2,3,4,5,6,7,8,9},
{10,11,12,13,14,15,16,17,18,19},
{20,21,22,23,24,25,26,27,28,29},
{30,31,32,33,34,35,36,37,38,39},
{40,41,42,43,44,45,46,47,48,49},
{50,51,52,53,54,55,56,57,58,59},
{60,61,62,63,64,65,66,67,68,69},
{70,71,72,73,74,75,76,77,78,79},
{80,81,82,83,84,85,86,87,88,89},
{90,91,92,93,94,95,96,97,98,99}
};
int input = 0;
int i = 0;
int sum = 0;
scanf("%d", &input);
for (i = 0; i < 10; i++) {
sum += *(*(A + i) + ((i + input) % 10));
}
printf("%d\n", sum);
return 0;
}

39
12/Exercise03.c Normal file
View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void output(char* start, char* end) {
char* ptr = start + 1;
for (;ptr < end; ptr++) {
printf("%c",*ptr);
}
printf("\n");
}
int main() {
char* inputStr = NULL;
char* startIndex = NULL;
char* p = NULL;
char startDelimiter, endDelimiter;
printf("转译符:");
scanf("%c", &startDelimiter);
printf("终止符:");
scanf(" %c", &endDelimiter);
getchar();
inputStr = malloc(141);
printf("输入文字:");
scanf("%[^\n]", inputStr);
p = inputStr;
while (p - inputStr < strlen(inputStr)) {
if (*p == startDelimiter) {
startIndex = p;
}
else if (*p == endDelimiter && startIndex != NULL) {
output(startIndex, p);
startIndex = NULL;
}
p++;
}
return 0;
}