This commit is contained in:
2023-09-23 22:20:41 +03:00
parent 609aa52e66
commit 66997adad5
42 changed files with 642 additions and 0 deletions

BIN
learnc/a.exe Executable file

Binary file not shown.

33
learnc/learnc1.c Executable file
View File

@ -0,0 +1,33 @@
#include <stdio.h>
int main() {
float average;
int grades[2][5];
int i;
int j;
grades[0][0] = 80;
grades[0][1] = 70;
grades[0][2] = 65;
grades[0][3] = 89;
grades[0][4] = 90;
grades[1][0] = 85;
grades[1][1] = 80;
grades[1][2] = 80;
grades[1][3] = 82;
grades[1][4] = 87;
/* TODO: complete the for loop with appropriate terminating conditions */
for (i = 0; i < 2; i++) {
average = 0;
for (j = 0; j < 5; j++) {
average += grades[i][j];
}
/* TODO: compute the average marks for subject i */
printf("The average marks obtained in subject %d is: %.2f\n", i, average);
}
return 0;
}

23
learnc/learnc10.c Executable file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
typedef struct {
char * name;
int age;
} person;
/* function declaration */
void birthday(person * p) {
p->age++;
}
int main() {
person john;
john.name = "John";
john.age = 27;
printf("%s is %d years old.\n", john.name, john.age);
birthday(&john);
printf("Happy birthday! %s is now %d years old.\n", john.name, john.age);
return 0;
}

19
learnc/learnc11.c Executable file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int x;
int y;
} point;
int main() {
point * mypoint;
mypoint = (point *)malloc(sizeof(point));
mypoint->x = 10;
mypoint->y =5 ;
printf("mypoint coordinates: %d, %d\n", mypoint->x, mypoint->y);
free(mypoint);
return 0;
}

17
learnc/learnc2.c Executable file
View File

@ -0,0 +1,17 @@
#include <stdio.h>
void guessNumber(int guess) {
if (guess == 555) {
printf("Correct. You guessed it!\n");
} if (guess < 555) {
printf("Your guess is too low.\n");
} if (guess > 555) {
printf("Your guess is too high.\n");
}
}
int main() {
guessNumber(500);
guessNumber(600);
guessNumber(555);
}

18
learnc/learnc3.c Executable file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <string.h>
int main() {
char first_name[5] = "John";
char last_name[4] = "Boe";
char name[100];
last_name[0] = 'B';
sprintf(name, "%s %s", first_name, last_name);
if (strncmp(name, "John Boe", 100) == 0) {
printf("Done!\n");
}
name[0]='\0';
strncat(name,first_name,4);
strncat(name,last_name,20);
printf("%s\n",name);
return 0;
}

13
learnc/learnc4.c Executable file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int factorial = 1;
int i;
for (i = 0; i < 10; i++) {
factorial *= array[i];
}
printf("10! is %d.\n", factorial);
}

22
learnc/learnc5.c Executable file
View File

@ -0,0 +1,22 @@
#include <stdio.h>
int main() {
int array[] = {1, 7, 4, 5, 9, 3, 5, 11, 6, 3, 4};
int i = 0;
while (i < 10) {
if (array[i] < 5){
i++;
continue;
}
if (array[i] < 10) {
printf("%d\n", array[i]);
i++;
if (array[i] > 10){
break;
}
}
}
return 0;
}

17
learnc/learnc6.c Executable file
View File

@ -0,0 +1,17 @@
#include <stdio.h>
void print_big(int number);
int main() {
int array[] = { 1, 11, 2, 22, 3, 33 };
int i;
for (i = 0; i < 6; i++) {
print_big(array[i]);
}
return 0;
}
void print_big(int number) {
if(number > 10) {
printf("%d is big\n",number);
}
}

13
learnc/learnc7.c Executable file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
int sum (int num) {
static int total = 0;
total += num;
return total;
}
int main() {
printf("%d ",sum(55));
printf("%d ",sum(45));
printf("%d ",sum(50));
return 0;
}

15
learnc/learnc8.c Executable file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
int n = 10;
int * pointer_to_n = &n;
n += 1;
/* testing code */
if (pointer_to_n != &n) return 1;
if (*pointer_to_n != 11) return 1;
printf("Done!\n");
return 0;
}

15
learnc/learnc9.c Executable file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
typedef struct {
char * name;
int age;
} person;
int main() {
person john;
/* testing code */
john.name = "John";
john.age = 27;
printf("%s is %d years old.", john.name, john.age);
}