diff --git a/a.exe b/a.exe new file mode 100755 index 0000000..03ca527 Binary files /dev/null and b/a.exe differ diff --git a/arrayfunc.c b/arrayfunc.c new file mode 100755 index 0000000..09e1a9d --- /dev/null +++ b/arrayfunc.c @@ -0,0 +1,21 @@ +#include + +void myFunc(int myNum[5]) { + for (int i = 0; i < 5; i++) { + printf("%d\n", myNum[i]); + } + + { + int i = 0; + while (i < 5) { + printf("%d\n", myNum[i]); + i++; + } + } +} + +int main() { + int myNum[5] = {25, 50, 75, 100, 125}; + myFunc(myNum); +return 0; +} \ No newline at end of file diff --git a/arrays.c b/arrays.c new file mode 100755 index 0000000..a2c296d --- /dev/null +++ b/arrays.c @@ -0,0 +1,12 @@ +#include + +int main() { + + int myNumbers[] = {11, 22, 33, 44, 55}; + printf("%d\n", myNumbers[4]); + int matrix[2][3] = { {1, 4, 9}, {2, 5, 7} }; + printf ("%d\n", matrix[1][2]); + printf ("%p", &myNumbers); + + return 0; + } diff --git a/booleans.c b/booleans.c new file mode 100755 index 0000000..01c8ab7 --- /dev/null +++ b/booleans.c @@ -0,0 +1,14 @@ +#include +#include +int main() { + int votingAge = 18; + int myAge = 18; + if (myAge > votingAge) { + printf("Oy verebilirsiniz!"); + } else if (myAge == votingAge) { + printf("test2"); + } else { + printf("test1"); + } + +} \ No newline at end of file diff --git a/charfunc.c b/charfunc.c new file mode 100755 index 0000000..3ff5bc0 --- /dev/null +++ b/charfunc.c @@ -0,0 +1,11 @@ +#include + +void myFunc(char name[], int age) { + printf("Hello %s. You're %d years old\n", name, age); +} + +int main() { + myFunc("Liam", 3); + myFunc("Ahmet", 30); +return 0; +} \ No newline at end of file diff --git a/declarition.c b/declarition.c new file mode 100755 index 0000000..358b51e --- /dev/null +++ b/declarition.c @@ -0,0 +1,13 @@ +#include + +int myFunc(int,int); + +int main(){ + int result = myFunc(5, 3); + printf("Result is %d", result); +return 0; +} + +int myFunc(int x, int y){ + return x + y; +} \ No newline at end of file diff --git a/fgets.c b/fgets.c new file mode 100755 index 0000000..bbd87a9 --- /dev/null +++ b/fgets.c @@ -0,0 +1,14 @@ +#include +int main() { + int test1; + char test2[50]; + char test3[50]; + + printf("Test box! : "); + fgets(test2, sizeof(test2), stdin); + printf("WORKING! : %s", test2); + printf("TEST2! : "); + fgets(test3, sizeof(test3), stdin); + printf("WORKING2!: %s", test3); +return 0; +} \ No newline at end of file diff --git a/file.c b/file.c new file mode 100755 index 0000000..2999d54 --- /dev/null +++ b/file.c @@ -0,0 +1,12 @@ +#include + +int main() { + + FILE *fptr; + + fptr = fopen("test1.txt", "a"); + fprintf(fptr, "\nThis is Working!"); + fclose(fptr); + +return 0; +} \ No newline at end of file diff --git a/fileopen.c b/fileopen.c new file mode 100755 index 0000000..0abf70d --- /dev/null +++ b/fileopen.c @@ -0,0 +1,16 @@ +#include + +int main () { + + FILE *fptr; + + fptr = fopen("test1.txt", "r"); + char myStr[100]; + + while(fgets(myStr, 100, fptr)) { + printf("%s", myStr); + } + fclose (fptr); + +return 0; +} \ No newline at end of file diff --git a/for loop.c b/for loop.c new file mode 100755 index 0000000..fc90ce1 --- /dev/null +++ b/for loop.c @@ -0,0 +1,15 @@ +#include + +int main() { + +int i, j; + +for (i = 1; i <= 2; ++i) { + printf("test: %d\n", i); + + for (j = 1; j <= 3; ++j) { + printf("test2 : %d\n", j); + } +} + return 0; +} \ No newline at end of file diff --git a/function.c b/function.c new file mode 100755 index 0000000..2574391 --- /dev/null +++ b/function.c @@ -0,0 +1,11 @@ +#include + +void myFunc() { + printf("My first Function!"); + +} + +int main() { + myFunc(); +return 0; +} \ No newline at end of file diff --git a/function2.c b/function2.c new file mode 100755 index 0000000..560356c --- /dev/null +++ b/function2.c @@ -0,0 +1,12 @@ +#include + +int myProg(int x) { + return x + 3; +} + +int main() { + + int y = 5; + printf("%d\n", myProg(y)); +return 0; +} \ No newline at end of file diff --git a/hello.c b/hello.c new file mode 100755 index 0000000..0bb36a3 --- /dev/null +++ b/hello.c @@ -0,0 +1,27 @@ +#include + +int main() { +// Learning C types +int myNum; +char myChar; +float myFloat; +myChar = 'a'; +myFloat = 1.55; +int myNumero = 11; +myNum = myNumero; +int x = 4; +int y = 10; +int suma = x + y; +int a = 10, b = 20, c = 30; +float sum = (float) y / x; +int myInt = 9.99; + //printf("My fav number is :%d\n", myNum); + printf("%lu\n", sizeof(myFloat)); + printf("%lu\n", sizeof(myChar)); + //printf("My fav number is: %d\t and My fav character is: %c\n", myNum, myChar); + printf("%lu\n", sizeof(suma)); + //printf("%d\n", a + b +c); + //printf("%.1f\n", sum); + printf("%lu\n", sizeof(myInt)); + return 0; +} \ No newline at end of file diff --git a/input.c b/input.c new file mode 100755 index 0000000..d76ec14 --- /dev/null +++ b/input.c @@ -0,0 +1,14 @@ +#include + +int main() { + + int sakiriNum; + char sakireDeger[30]; + printf("Please, enter a number: \n"); + scanf("%d", &sakiriNum); + printf("Please, enter your name: \n"); + scanf("%s", sakireDeger); + printf("You pressed sakir: %d,", sakiriNum); + printf(" %s!", sakireDeger); +return 0; +} \ No newline at end of file diff --git a/learnc/a.exe b/learnc/a.exe new file mode 100755 index 0000000..194a1b0 Binary files /dev/null and b/learnc/a.exe differ diff --git a/learnc/learnc1.c b/learnc/learnc1.c new file mode 100755 index 0000000..75e85f1 --- /dev/null +++ b/learnc/learnc1.c @@ -0,0 +1,33 @@ + #include + + 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; + } diff --git a/learnc/learnc10.c b/learnc/learnc10.c new file mode 100755 index 0000000..73ddb24 --- /dev/null +++ b/learnc/learnc10.c @@ -0,0 +1,23 @@ +#include + +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; +} \ No newline at end of file diff --git a/learnc/learnc11.c b/learnc/learnc11.c new file mode 100755 index 0000000..ca4adaf --- /dev/null +++ b/learnc/learnc11.c @@ -0,0 +1,19 @@ +#include +#include + +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; +} \ No newline at end of file diff --git a/learnc/learnc2.c b/learnc/learnc2.c new file mode 100755 index 0000000..5816088 --- /dev/null +++ b/learnc/learnc2.c @@ -0,0 +1,17 @@ +#include + +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); +} diff --git a/learnc/learnc3.c b/learnc/learnc3.c new file mode 100755 index 0000000..5c92644 --- /dev/null +++ b/learnc/learnc3.c @@ -0,0 +1,18 @@ +#include +#include +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; +} diff --git a/learnc/learnc4.c b/learnc/learnc4.c new file mode 100755 index 0000000..a41fc87 --- /dev/null +++ b/learnc/learnc4.c @@ -0,0 +1,13 @@ +#include + +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); +} diff --git a/learnc/learnc5.c b/learnc/learnc5.c new file mode 100755 index 0000000..5c9b803 --- /dev/null +++ b/learnc/learnc5.c @@ -0,0 +1,22 @@ +#include + +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; +} diff --git a/learnc/learnc6.c b/learnc/learnc6.c new file mode 100755 index 0000000..3073631 --- /dev/null +++ b/learnc/learnc6.c @@ -0,0 +1,17 @@ +#include + +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); +} +} diff --git a/learnc/learnc7.c b/learnc/learnc7.c new file mode 100755 index 0000000..9d2989b --- /dev/null +++ b/learnc/learnc7.c @@ -0,0 +1,13 @@ + #include + 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; + } \ No newline at end of file diff --git a/learnc/learnc8.c b/learnc/learnc8.c new file mode 100755 index 0000000..241099a --- /dev/null +++ b/learnc/learnc8.c @@ -0,0 +1,15 @@ +#include + +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; +} \ No newline at end of file diff --git a/learnc/learnc9.c b/learnc/learnc9.c new file mode 100755 index 0000000..f43ec24 --- /dev/null +++ b/learnc/learnc9.c @@ -0,0 +1,15 @@ +#include + +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); +} \ No newline at end of file diff --git a/loop.c b/loop.c new file mode 100755 index 0000000..98ded5f --- /dev/null +++ b/loop.c @@ -0,0 +1,11 @@ +#include +int main() { + int i = 0; + +while (i >= 5) { + + printf("%d\n", i); + i++; +} + +} \ No newline at end of file diff --git a/math.c b/math.c new file mode 100755 index 0000000..eb63013 --- /dev/null +++ b/math.c @@ -0,0 +1,16 @@ +#include +#include + +int myProg(int, int); + +int main(){ + float fullNum; + int b; + + printf("Lutfen rakam giriniz! \n"); + scanf("%f\n", &fullNum); + printf("%f\n", ceil(fullNum)); + printf("%f", floor(fullNum)); +return 0; + +} \ No newline at end of file diff --git a/matrix.c b/matrix.c new file mode 100755 index 0000000..db2940f --- /dev/null +++ b/matrix.c @@ -0,0 +1,13 @@ +#include + +int main() { + + int matrix[2][3] = { {1, 2, 3}, {4, 5, 6} }; + int i,j; + for (i = 0; i < 2; i++) { + for (j = 0; j < 3; j++) { + printf ("%d\n", matrix[i][j]); + } + } + return 0; +} \ No newline at end of file diff --git a/pointer.c b/pointer.c new file mode 100755 index 0000000..5d335a7 --- /dev/null +++ b/pointer.c @@ -0,0 +1,14 @@ +#include + +int main () { + + int speedTrain = 150; + int* ptr = &speedTrain; + + printf("%d\n", speedTrain); + printf("%p\n", &speedTrain); + printf("%p\n", ptr); + printf("%d\n", *ptr); + +return 0; +} \ No newline at end of file diff --git a/pointerarrays.c b/pointerarrays.c new file mode 100755 index 0000000..0cdc64b --- /dev/null +++ b/pointerarrays.c @@ -0,0 +1,16 @@ +#include + +int main() { + int myNum[4] = {25, 50, 75, 100}; + int i; + int j; + + for (i = 0; i < 4; i++) { + printf("%p\n", &myNum[i]); + } + printf("%lu\n", sizeof(j)); + printf("%p\n", myNum); + printf("%p\n", &myNum[0]); + printf("%lu\n", sizeof(myNum)); +return 0; +} \ No newline at end of file diff --git a/pointerarrays2.c b/pointerarrays2.c new file mode 100755 index 0000000..fa78b73 --- /dev/null +++ b/pointerarrays2.c @@ -0,0 +1,15 @@ +#include +int main() { + + int myNumbers[4] = {25, 50, 75, 100}; + int *ptr = myNumbers; + int i; + *myNumbers = 101; + *(myNumbers + 1) = 55; + + for (i = 0; i < 4; i++) { + printf("%d\n", *(ptr + i)); + } + printf("%d\n", *(myNumbers + 1)); +return 0; +} \ No newline at end of file diff --git a/recursion.c b/recursion.c new file mode 100755 index 0000000..3874626 --- /dev/null +++ b/recursion.c @@ -0,0 +1,22 @@ +#include + +int myProg(int k); + +int main() { + int b; + printf("Type a num: \n"); + scanf("%d", &b); + int result = myProg(b); + printf("%d\n", result); +return 0; + +} + +int myProg(int k) { + if (k > 10) { + return k + myProg(k - 1); + } else { + return 0; + } + +} \ No newline at end of file diff --git a/specialstrings.c b/specialstrings.c new file mode 100755 index 0000000..438c09a --- /dev/null +++ b/specialstrings.c @@ -0,0 +1,7 @@ +#include + +int main () { + char txt[] = "If i live in a \"different\" universe i love you"; + printf ("%s", txt); +return 0; +} \ No newline at end of file diff --git a/string.c b/string.c new file mode 100755 index 0000000..991f66a --- /dev/null +++ b/string.c @@ -0,0 +1,10 @@ +#include +#include + +int main () { + char test[40] = "TESTING"; + char test2[50] = " WORKING"; + char test3[50] = "TESTING"; + printf("%d", strcmp(test, test3)); +return 0; +} \ No newline at end of file diff --git a/strings.c b/strings.c new file mode 100755 index 0000000..9179c64 --- /dev/null +++ b/strings.c @@ -0,0 +1,8 @@ +#include + +int main () { + char greetings[] = "Hello!"; + greetings[0] = 'Y'; + printf("%s\n", greetings); +return 0; +} \ No newline at end of file diff --git a/stringsloop.c b/stringsloop.c new file mode 100755 index 0000000..e8ca2a8 --- /dev/null +++ b/stringsloop.c @@ -0,0 +1,17 @@ +#include + +int main () { + char carName[] = "GOLF"; + int i; + int j = 0; + while (j < 5) { + + for (i = 0; i < 5; i++) { + printf ("%c\t", carName[i]); + + } + printf ("\n"); + j++; + } +return 0; +} \ No newline at end of file diff --git a/structer.c b/structer.c new file mode 100755 index 0000000..7265e95 --- /dev/null +++ b/structer.c @@ -0,0 +1,28 @@ +#include +#include + +struct myStruct { + int myNum; + char myLtr; + char myString[30]; +}; + +int main () { + + struct myStruct s1; + s1.myNum = 10; + s1.myLtr = 'a'; + strcpy(s1.myString, "Greetings!"); + + struct myStruct s2; + s2.myNum = 19; + s2.myLtr = 'C'; + + printf("%s\n", s1.myString); + printf("%d\n", s1.myNum); + printf("%c\n", s1.myLtr); + printf("%d\n", s2.myNum); + printf("%c\n", s2.myLtr); + +return 0; +} \ No newline at end of file diff --git a/structer2.c b/structer2.c new file mode 100755 index 0000000..ffa9090 --- /dev/null +++ b/structer2.c @@ -0,0 +1,17 @@ +#include +#include + +struct myStruct { + int myNum; + char myNam[30]; +}; + + +int main () { + + struct myStruct s3 = {15, "Hello World!"}; + printf("%d\n%s", s3.myNum, s3.myNam); + + return 0; + +} \ No newline at end of file diff --git a/switch.c b/switch.c new file mode 100755 index 0000000..2db459a --- /dev/null +++ b/switch.c @@ -0,0 +1,42 @@ +#include +int main() { + int day = 8; + + + switch (day) { + + case 1: + printf("monday"); + break; + + case 2: + printf("tuesday"); + break; + + case 3: + printf("wednesday"); + break; + + case 4: + printf("thursday"); + break; + + case 5: + printf("friday"); + break; + + case 6: + printf("saturday"); + break; + + case 7: + printf("sunday"); + break; + + default: + printf("there's 7 day in week!"); + + } + + +} \ No newline at end of file diff --git a/test1.txt b/test1.txt new file mode 100755 index 0000000..cabb56a --- /dev/null +++ b/test1.txt @@ -0,0 +1,2 @@ +Hello World! +This is Working! \ No newline at end of file diff --git a/test2.c b/test2.c new file mode 100755 index 0000000..2e93373 --- /dev/null +++ b/test2.c @@ -0,0 +1,7 @@ +#include + int main() { +int x = 7; +int y = 5; +printf ("%d\n", !(x > 4 && y > 4)); + + }