Train
unknown
c_cpp
2 years ago
7.6 kB
32
Indexable
#include <stdio.h>
#include <string.h>
int main()
{
printf("\n\nTest1\n");
main1();
printf("\n\nTest2\n");
main2();
printf("\n\nTest3\n");
main3();
printf("\n\nTest4\n");
main4();
printf("\n\nTest5\n");
main5();
printf("\n\nTest6\n");
main6();
printf("\n\nTest7\n");
main7();
printf("\n\nTest8\n");
main8();
printf("\n\nTest9\n");
main9();
printf("\n\nTest10\n");
main10();
return 0;
}
void main1()
{
int a[] = {6, 5, 4, 3, 2, 1};
char *b[] = {"trust", "i", "seek", "and", "i", "find", "in", "you"};
char *c = "happy";
char *d[] = {b[a[2]], b[a[0]], b[a[0] - a[5]]};
int e[2][3] = {{0, 3, 4}, {1, 2, 7}};
int f[] = {b[3][2] - b[4][0], a[2] + a[4], e[1][2] - e[0][1]};
char *g = b[3];
printf("%d\n", c[1]);
printf("%d\n", a[2]);
printf("%d\n", f[2] + *(f + 1));
printf("%d\n", *(f + a[5]));
printf("%c\n", **(d + 1));
printf("%s\n", (g + 1));
printf("%c\n", (g + 1)[1]);
}
void main2()
{
int x[] = {8, 7, 6, 5, 4, 3};
char *y[] = {"create", "hope", "discover", "believe", "reflect", "embrace"};
char *z = "growth";
char *w[] = {y[x[1]], y[x[2]], y[x[4] - x[5]]};
int u[2][3] = {{1, 4, 5}, {0, 2, 6}};
int v[] = {y[1][1] - y[2][3], x[1] + x[3], u[1][2] - u[0][0]};
printf("%d\n", z[3]);
printf("%d\n", x[3]);
printf("%d\n", v[1] + *(v + 2));
printf("%d\n", *(v + x[5]));
printf("%c\n", **(w + 2));
printf("%s\n", y[4] + 2);
printf("%c\n", y[3][2]);
}
void main3()
{
int alpha[] = {12, 11, 10, 9, 8, 7};
char *beta[] = {"innovation", "vision", "harmony", "insight", "courage", "persistence"};
char *gamma = "challenge";
char *delta[] = {beta[alpha[3] % 5], beta[alpha[1]], beta[alpha[4] - alpha[5]], gamma + 4};
int epsilon[2][3] = {{2, 5, 8}, {1, 3, 7}};
int zeta[] = {beta[1][epsilon[0][1]] - beta[2][epsilon[1][0]], alpha[epsilon[1][1]] - alpha[epsilon[0][0]], epsilon[0][2] * epsilon[1][2]};
printf("%d\n", gamma[2] * gamma[5]);
printf("%s\n", delta[2] + 3);
printf("%d\n", zeta[2] / zeta[1]);
printf("%c\n", beta[4][alpha[5] % 7]);
printf("%s\n", delta[1] + (alpha[2] % 5));
printf("%c\n", *(gamma + (zeta[0] % 10)));
printf("%d\n", *((int*)delta[3] + 1));
}
void main4()
{
int matrix[3][3] = {{5, 9, 2}, {6, 3, 8}, {7, 4, 1}};
char *words[] = {"dynamic", "creative", "efficient", "logical"};
char letters[] = "ABCD";
int *ptrMatrix = (int *)matrix;
char **ptrWords = words;
char *ptrLetters = letters;
printf("%d\n", *(ptrMatrix + 4));
printf("%c\n", letters[(int)strlen(*(ptrWords + 2)) - 1]);
printf("%s\n", *(ptrWords + (matrix[2][1] % 3)));
printf("%c\n", *(ptrLetters + matrix[0][2]));
for (int i = 0; i < 9; i++) {
if (*(ptrMatrix + i) % 2 == 0) {
*(ptrMatrix + i) *= -1;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
ptrLetters += 2;
printf("%s\n", ptrLetters);
printf("%c\n", **(ptrWords + 1));
}
void main5()
{
int matrix[3][3] = {{5, 9, 2}, {6, 3, 8}, {7, 4, 1}};
char *words[] = {"dynamic", "creative", "efficient", "logical"};
char letters[] = "ABCD";
int *ptrMatrix = (int *)matrix;
char **ptrWords = words;
char *ptrLetters = letters;
printf("%d\n", *(ptrMatrix + 4));
printf("%c\n", letters[(int)strlen(*(ptrWords + 2)) - 1]);
printf("%s\n", *(ptrWords + (matrix[2][1] % 3)));
printf("%c\n", *(ptrLetters + matrix[0][2]));
for (int i = 0; i < 9; i++) {
if (*(ptrMatrix + i) % 2 == 0) {
*(ptrMatrix + i) *= -1;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
ptrLetters += 2;
printf("%s\n", ptrLetters);
printf("%c\n", **(ptrWords + 1));
}
void main6()
{
int values[] = {10, 20, 30, 40, 50};
char *words[] = {"ambition", "bravery", "clarity", "determination"};
char symbols[] = "MNOP";
int matrix[3][2] = {{values[2], values[0]}, {values[1], values[3]}, {values[4], values[2] - values[1]}};
int *ptrValues = values;
char **ptrWords = words;
char *ptrSymbols = symbols;
printf("%c\n", ptrSymbols[values[0] / 20]);
printf("%s\n", ptrWords[matrix[0][0] / 10]);
printf("%d\n", matrix[1][ptrSymbols[1] - 'M']);
printf("%c\n", symbols[strlen(words[2]) - 3]);
for (int i = 0; i < 5; i++) {
ptrValues[i] = matrix[i % 3][i / 3] * (i + 1);
}
for (int i = 0; i < 5; i++) {
printf("%d ", ptrValues[i]);
}
printf("\n");
printf("%s\n", words[(ptrValues[3] - 40) / 10]);
printf("%c\n", *(ptrSymbols + 2) + 1);
}
void main7()
{
int numbers[] = {2, 4, 6, 8, 10};
char *words[] = {"apple", "banana", "cherry", "date"};
int *ptrNumbers = numbers;
char **ptrWords = words;
printf("%d\n", *(ptrNumbers + 2));
printf("%s\n", *(ptrWords + 1));
*(ptrNumbers + 1) = 5;
for (int i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}
printf("\n");
printf("%c\n", *(*(ptrWords + 2) + 1));
ptrNumbers += 3;
printf("%d\n", *ptrNumbers);
}
// Function to modify array elements
void modifyArray(int *arr, int size) {
for (int i = 0; i < size; i++) {
arr[i] = (arr[i] % 3 == 0) ? arr[i] + 3 : arr[i] - 2;
}
}
void main8() {
int nums[] = {12, 15, 18, 21, 24};
char *strings[] = {"alpha", "beta", "gamma", "delta"};
char letters[] = "HELLO";
int *pNums = nums;
char **pStrings = strings;
char *pLetters = letters;
printf("%c\n", pLetters[*(pNums + 1) % 5]);
modifyArray(nums, 5);
printf("%s\n", *(pStrings + (nums[2] % 4)));
for (int i = 0; i < 5; i++) {
if (pNums[i] % 4 == 0) {
pNums[i] = (int)*(pLetters + i);
}
}
for (int i = 0; i < 5; i++) {
printf("%d ", nums[i]);
}
printf("\n");
printf("%c\n", *(pStrings[0] + nums[0] % 5));
printf("%c\n", letters[nums[3] % 5]);
}
void main9() {
char words[3][2][10] = {
{"hello", "world"},
{"good", "morning"},
{"good", "night"}
};
printf("%s\n", words[1][1]);
printf("%s\n", words[2][1]);
words[0][1][0] = 'W';
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
printf("%s ", words[i][j]);
}
printf("\n");
}
printf("%c\n", words[0][1][1]);
printf("%c\n", words[2][0][2]);
}
void changeFirstChar(char phrases[2][3][10], int row, int col) {
phrases[row][col][0] += 1; // Incrementing the first character of the selected string
}
void main10() {
char phrases[2][3][10] = {
{"spring", "summer", "autumn"},
{"winter", "rainy", "sunny"}
};
printf("%s\n", phrases[0][2]);
printf("%s\n", phrases[1][1]);
changeFirstChar(phrases, 1, 0);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
printf("%s ", phrases[i][j]);
}
printf("\n");
}
printf("%c\n", phrases[1][2][3]);
printf("%c\n", phrases[0][1][2]);
}
Editor is loading...
Leave a Comment