├── README.md ├── lesson01 ├── c_language_lesson_1(4sl).pdf ├── c_language_lesson_1.pdf ├── hello.c ├── radius.c └── triangle.c ├── lesson02 ├── c_language_lesson_2(4sl).pdf ├── c_language_lesson_2.pdf ├── multiply.c ├── numbers.c └── print.c ├── lesson03 ├── c_language_lesson_3(4sl).pdf ├── c_language_lesson_3.pdf ├── efarmogi1.c ├── print.c ├── sizes.c ├── statheres.c └── typedef.c ├── lesson04 ├── c_language_lesson_4(4sl).pdf ├── c_language_lesson_4.pdf ├── efarmogi1_age.c ├── efarmogi1_age_2.c ├── efarmogi2_max2.c ├── efarmogi3_max3_a.c ├── efarmogi3_max3_b.c ├── efarmogi3_max3_c.c ├── efarmogi4_sort3.c ├── efarmogi5.c ├── efarmogi6.c ├── efarmogi6_2nd.c ├── efarmogi7.c ├── if_01.c ├── if_02.c ├── if_03.c ├── logikoi.c ├── monadiaioi.c ├── prakseis.c ├── sxesiakoi.c └── ternary.c ├── lesson05 ├── array.c ├── array2.c ├── c_language_lesson_5(4sl).pdf ├── c_language_lesson_5.pdf ├── complex_for.c ├── defensive.c ├── dowhile.c ├── efarmogi1.c ├── efarmogi1_b.c ├── efarmogi1_c.c ├── efarmogi2.c ├── efarmogi3.c ├── efarmogi3_b.c ├── efarmogi4.c ├── efarmogi4_b.c ├── efarmogi5.c ├── efarmogi6.c ├── efarmogi7.c ├── efarmogi8.c └── for.c ├── lesson06 ├── c_language_lesson_6(4sl).pdf ├── c_language_lesson_6.pdf ├── efarmogi1.c ├── efarmogi2.c ├── efarmogi3.c ├── efarmogi4.c ├── efarmogi5.c ├── factorial.c ├── orismata.c └── variables.c ├── lesson07 ├── array.c ├── array2.c ├── c_language_lesson_7_arrays(4sl).pdf ├── c_language_lesson_7_arrays.pdf ├── efarmogi1_array1d.c ├── efarmogi2_array2d.c ├── efarmogi3_array2d_def.c ├── efarmogi4_hidden.c └── random.c ├── lesson08 ├── array_ref.c ├── byreference.c ├── byvalue.c ├── c_language_lesson_8_pointers(4sl).pdf ├── c_language_lesson_8_pointers.pdf ├── efarmogi1_rizes.c ├── efarmogi2-5.c ├── matrix_pointers.c ├── null.c ├── pointer_calc.c └── pointers.c ├── lesson09 ├── advanced.c ├── c_language_lesson_9_print_scan(4sl).pdf ├── c_language_lesson_9_print_scan.pdf ├── dekadika.c ├── efarmogi1.c ├── efarmogi2.c ├── efarmogi3.c ├── efarmogi3_dies.c ├── prosd.c ├── special.c └── width_precision.c ├── lesson10 ├── c_language_lesson_10_ascii.pdf ├── c_language_lesson_10_strings(4sl).pdf ├── c_language_lesson_10_strings.pdf ├── char.c ├── efarmogi1_mystrlen.c ├── efarmogi2_mystrcpy.c ├── efarmogi3_capitalize.c ├── efarmogi4_ascii_table.c ├── efarmogi5_string_compare.c ├── string.c └── string2.c ├── lesson11 ├── break.c ├── c_language_lesson_11_program_flow(4sl).pdf ├── c_language_lesson_11_program_flow.pdf ├── continue.c ├── efarmogi1_menu.c ├── efarmogi2,3_menu.c ├── goto.c └── wrong_switch.c ├── lesson12 ├── askisi2.c ├── askisi3.c ├── askisi4.c ├── c_language_lesson_12_malloc(4sl).pdf ├── c_language_lesson_12_malloc.pdf ├── efarmogi1.c ├── malloc_1d-array.c ├── malloc_2d-array.c └── malloc_var.c ├── lesson13 ├── c_language_lesson_13_structs(4sl).pdf ├── c_language_lesson_13_structs.pdf ├── efarmogi1.c ├── efarmogi2.c ├── efarmogi3.c ├── efarmogi4.c ├── efarmogi5.c ├── efarmogi6.c ├── struct.c ├── struct_array.c └── union.c ├── lesson14 ├── c_language_lesson_14_emveleia(4sl).pdf ├── c_language_lesson_14_emveleia.pdf ├── efarmogi1.c ├── global.c ├── lib_array.c ├── lib_array.h ├── local.c ├── main.c ├── manip_array.dev ├── orismata.c ├── record.c ├── record.dev ├── record.h ├── record_main.c └── static.c ├── lesson15 ├── askisi1.c ├── askisi2.c ├── c_language_lesson_15_sinartiseis_input(4sl).pdf ├── c_language_lesson_15_sinartiseis_input.pdf ├── fflush.c ├── fflush_wrong.c ├── fgets.c ├── getch.c ├── getchar.c ├── getche.c ├── scanf.c ├── test.c └── ungetc.c ├── lesson16 ├── askisi3.c ├── c_language_lesson_16_sinartiseis_output(4sl).pdf ├── c_language_lesson_16_sinartiseis_output.pdf ├── efarmogi1.c ├── efarmogi2.c ├── fprintf.c ├── fputc.c ├── putchar.c └── puts.c ├── lesson17 ├── argc_argv.c ├── argc_argv_loop.c ├── atoi.c ├── c_language_lesson_17_leitourgiko_sistima(4sl).pdf ├── c_language_lesson_17_leitourgiko_sistima.pdf ├── efarmogi1.c ├── efarmogi2.c ├── file.txt ├── redirect_input.c └── redirect_output.c ├── lesson18 ├── C.18(4sl).pdf ├── C.18.pdf ├── ask1.c ├── ask2.c ├── strcat.c ├── strchr.c ├── strcmp.c ├── strcpy.c ├── strcspn.c ├── strdup.c ├── strlen.c ├── strncat.c ├── strncmp.c ├── strncpy.c ├── strrchr.c ├── strspn.c ├── strstr.c └── strtok.c ├── lesson19 ├── C.19(4sl).pdf ├── C.19.pdf ├── askisi1.c ├── askisi2.c ├── clock.c ├── math.exp.c ├── math.floor-ceil.c ├── math.frexp.c ├── math.modf.c ├── math.sqrt.c ├── math.trig.c ├── time.c ├── time.convert.c ├── time.print.c └── time.timer_program.c ├── lesson20 ├── askisi1.1.c ├── askisi1.2.c ├── askisi1.3.c ├── askisi2.c ├── askisi3.c ├── binarydata.dat ├── c20(4sl).pdf ├── c20.pdf ├── data.dat ├── feof.c ├── feof_binary.c ├── fgetc.c ├── fprintf.c ├── fread.c ├── fscanf.c ├── fseek.c ├── ftell.c ├── fwrite.c ├── points.txt ├── rewind.c └── temp.txt ├── lesson21 ├── askisi.3.cpp ├── askisi1.c ├── askisi2.c ├── bits_in_struct.c ├── c21(4sl).pdf ├── c21.pdf ├── generic_pointer.c ├── realloc.c ├── va_arg.c ├── voidptr_accessing_struct.c ├── voidptr_inc.c └── voidptr_printing.c ├── lesson22 ├── askisi1.c ├── askisi2.c ├── askisi3.c ├── bits_get_function.c ├── bits_get_function_shift.c ├── bits_get_function_shift_and.c ├── bits_in_char.c ├── bits_set_function.c ├── c22(4sl).pdf ├── c22.pdf └── test.txt ├── lesson23 ├── array_of_functions.c ├── askisi1.c ├── askisi2.c ├── c23(sl).pdf ├── c23.pdf ├── class.c ├── function_with_arg_pointer.c ├── perror.c ├── pointer_to_diff_functions.c ├── pointer_to_function.c └── typedef_pointer_function.c ├── lesson24 ├── askisi1.c ├── c24(4sl).pdf ├── c24.pdf ├── errno.c ├── stderr.c ├── stderr2.c └── strerror.c └── lesson25 ├── c25(4sl).pdf ├── c25.pdf ├── macro_function.c ├── macro_function2.c ├── macro_function3.c ├── macro_function4.c ├── project1 ├── Makefile.win ├── h.c ├── h.h ├── h.o ├── h1.c ├── h1.h ├── h1.o ├── h2.c ├── h2.h ├── h2.o ├── main.c ├── project1.dev └── project1.layout └── project2 ├── Makefile.win ├── askisi1.c ├── askisi1.exe ├── askisi2.c ├── askisi2.exe ├── h.c ├── h.h ├── h.o ├── h1.c ├── h1.h ├── h1.o ├── h2.c ├── h2.h ├── h2.o ├── main.c ├── main.o ├── project2.dev ├── project2.exe └── project2.layout /README.md: -------------------------------------------------------------------------------- 1 | # C-programming 2 | Κώδικας Μαθημάτων Προγραμματισμού C στο youtube 3 | -------------------------------------------------------------------------------- /lesson01/c_language_lesson_1(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson01/c_language_lesson_1(4sl).pdf -------------------------------------------------------------------------------- /lesson01/c_language_lesson_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson01/c_language_lesson_1.pdf -------------------------------------------------------------------------------- /lesson01/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Hello World! \n"); 5 | return 0; 6 | } 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /lesson01/radius.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int radius, area; 4 | 5 | int main() { 6 | printf("Eisagete tin aktina:"); 7 | scanf("%d",&radius); 8 | area=(int)3.1415 * radius * radius; 9 | printf("\n\nTo emvadon einai: %d\n", area); 10 | 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lesson01/triangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int i,j; 4 | 5 | int main() { 6 | for (i=1; i<=90; i++) { 7 | for (j=1; j<=i; j++) 8 | printf("X"); 9 | printf("\n"); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /lesson02/c_language_lesson_2(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson02/c_language_lesson_2(4sl).pdf -------------------------------------------------------------------------------- /lesson02/c_language_lesson_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson02/c_language_lesson_2.pdf -------------------------------------------------------------------------------- /lesson02/multiply.c: -------------------------------------------------------------------------------- 1 | /* Multiply.c: Programma gia ton ipologismo tou ginomenou dio arithmwn */ 2 | #include 3 | 4 | int a,b,c; 5 | 6 | int ginomeno(int x, int y); 7 | 8 | main() 9 | { 10 | /* Eisodos toy 1ou arithmou */ 11 | printf("Eisagete arithmo metaksi 1 kai 100:"); 12 | scanf("%d", &a); 13 | 14 | /* Eisodos tou 2ou arithmou */ 15 | printf("Eisagete allon ena arithmo metaksi 1 kai 100:"); 16 | scanf("%d", &b); 17 | 18 | c=ginomeno(a,b); 19 | printf("To ginomeno tou %d kai tou %d einai: %d\n",a,b,c); 20 | 21 | } 22 | 23 | /* H synartisi epistrefei to ginomeno twn dio orismatwn tis */ 24 | int ginomeno(int x, int y) 25 | { 26 | return (x*y); 27 | } 28 | -------------------------------------------------------------------------------- /lesson02/numbers.c: -------------------------------------------------------------------------------- 1 | /* numbers.c */ 2 | #include 3 | 4 | main() 5 | { 6 | int i,N,y; 7 | 8 | printf("Eisagete enan akeraio arithmo: "); 9 | scanf("%d",&N); 10 | 11 | for (i=1; i<=N; i++) 12 | { 13 | y=i*i; 14 | printf("\n%d sto tetragono = %d",i,y); 15 | } 16 | 17 | printf("\n\nTelos Programmatos"); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lesson02/print.c: -------------------------------------------------------------------------------- 1 | /* print.c: Programma gia ektiposi grammwn */ 2 | #include 3 | 4 | int x; 5 | 6 | void grammi(); 7 | 8 | main() 9 | { 10 | // Ektyposeis... 11 | grammi(); 12 | printf("\nSe posa mathimata thelete na mathete tin C? "); 13 | scanf("%d", &x); 14 | grammi(); 15 | 16 | printf("\nTha apaitithoun 20 mathimata!"); 17 | grammi(); 18 | printf("\nApantisate %d",x); 19 | grammi(); 20 | } 21 | 22 | /* H synartisi ektiponei mia grammi */ 23 | void grammi() 24 | { 25 | printf("\n==============================="); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lesson03/c_language_lesson_3(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson03/c_language_lesson_3(4sl).pdf -------------------------------------------------------------------------------- /lesson03/c_language_lesson_3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson03/c_language_lesson_3.pdf -------------------------------------------------------------------------------- /lesson03/efarmogi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | const int x=100; 6 | int y; 7 | 8 | printf("Dwse tin timi tis metavlitis: "); 9 | scanf("%d",&y); 10 | printf("stathera=%d, metavliti=%d", x,y); 11 | } 12 | -------------------------------------------------------------------------------- /lesson03/print.c: -------------------------------------------------------------------------------- 1 | /* print.c: Statheres kai metavlites */ 2 | #include 3 | 4 | main() 5 | { 6 | const int x=100; 7 | int a; 8 | 9 | scanf("%d",&a); 10 | 11 | printf("Stathera=%d, Metavliti=%d",x,a); 12 | } 13 | -------------------------------------------------------------------------------- /lesson03/sizes.c: -------------------------------------------------------------------------------- 1 | /* sizes.c: Provallei stin othoni ta megethi se bytes twn tipwn dedomenvn */ 2 | #include 3 | 4 | main() 5 | { 6 | printf("\nTa bytes enos char einai: %d", sizeof(char)); 7 | printf("\nTa bytes enos short einai: %d", sizeof(short)); 8 | printf("\nTa bytes enos int einai: %d", sizeof(int)); 9 | printf("\nTa bytes enos long einai: %d", sizeof(long)); 10 | 11 | printf("\nTa bytes enos unsigned short einai: %d", sizeof(unsigned short)); 12 | printf("\nTa bytes enos unsigned int einai: %d", sizeof(unsigned int)); 13 | printf("\nTa bytes enos unsigned long einai: %d", sizeof(unsigned long)); 14 | 15 | printf("\nTa bytes enos float einai: %d", sizeof(float)); 16 | printf("\nTa bytes enos double einai: %d", sizeof(double)); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /lesson03/statheres.c: -------------------------------------------------------------------------------- 1 | /* statheres.c: Programma poy deixnei tin xrisi statherwn */ 2 | 3 | #include //1.grafoume ta arxeia kefalidas 4 | 5 | #define N 100 //2.Grafoume odigies define statherwn 6 | 7 | //3. Edw mporoume na orisoume katholikes metavlites 8 | 9 | //4. Edw mporoume na orisoyme prwtotipa sinartisewn 10 | 11 | main() 12 | { 13 | //5.1 Dilwsi statherwn kai metavlitwn tis main 14 | int i,sum; 15 | const int number=10; 16 | 17 | //5.2 entoles tis main 18 | 19 | sum=0; 20 | for (i=number; i<=N; i++) 21 | sum=sum+i; 22 | 23 | printf("To athroisma twn arithmwn [%d..%d] einai %d",number,N,sum); 24 | } 25 | 26 | //6. Edw tha exoyme ta swmata twn sinartisewn 27 | 28 | -------------------------------------------------------------------------------- /lesson03/typedef.c: -------------------------------------------------------------------------------- 1 | /* typedef.c: Paradeigma xrisis tis entolis typedef */ 2 | 3 | #include 4 | 5 | typedef int akeraios; 6 | 7 | main() 8 | { 9 | akeraios x,y,z; 10 | 11 | printf("Dwste enan akeraio: "); 12 | scanf("%d",&x); 13 | printf("Dwste akomi enan akeraio: "); 14 | scanf("%d",&y); 15 | z=x+y; 16 | printf("To athroisma toys einai: %d", z); 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lesson04/c_language_lesson_4(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson04/c_language_lesson_4(4sl).pdf -------------------------------------------------------------------------------- /lesson04/c_language_lesson_4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson04/c_language_lesson_4.pdf -------------------------------------------------------------------------------- /lesson04/efarmogi1_age.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int age; 6 | 7 | printf("Dwse tin ilikia sou: "); 8 | scanf("%d",&age); 9 | 10 | if (age<18) 11 | { 12 | printf("Eisai Anilikos!"); 13 | } 14 | else 15 | { 16 | if (age<=65) 17 | { 18 | printf("Eisai enilikos!"); 19 | } 20 | else 21 | { 22 | printf("Eisai sintaksiouxos!"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lesson04/efarmogi1_age_2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int age; 6 | 7 | printf("Dwse tin ilikia sou: "); 8 | scanf("%d",&age); 9 | 10 | if (age<18) 11 | printf("Eisai Anilikos!"); 12 | else if (18<=age && age<=65) 13 | printf("Eisai enilikos!"); 14 | else // age>65 15 | printf("Eisai sintaksiouxos!"); 16 | } 17 | -------------------------------------------------------------------------------- /lesson04/efarmogi2_max2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int x,y; 6 | 7 | printf("Dwse ton 1o arithmo: "); 8 | scanf("%d", &x); 9 | 10 | printf("Dwse ton 2o arithmo: "); 11 | scanf("%d", &y); 12 | 13 | 14 | if (x>y) 15 | printf("O megaliteros einai o %d",x); 16 | else // y>=x 17 | printf("O megaliteros einai o %d",y); 18 | } 19 | -------------------------------------------------------------------------------- /lesson04/efarmogi3_max3_a.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int x,y,z; 6 | 7 | printf("Dwse ton 1o arithmo: "); 8 | scanf("%d", &x); 9 | 10 | printf("Dwse ton 2o arithmo: "); 11 | scanf("%d", &y); 12 | 13 | printf("Dwse ton 3o arithmo: "); 14 | scanf("%d", &z); 15 | 16 | 17 | if (x>y) 18 | { 19 | if (x>z) 20 | { 21 | printf("O megaliteros einai to %d", x); 22 | } 23 | else // z>=x 24 | { 25 | printf("O megaliteros einai to %d", z); 26 | } 27 | } 28 | else // y>=x 29 | { 30 | if (y>z) 31 | { 32 | printf("O megaliteros einai to %d", y); 33 | } 34 | else // z>=y 35 | { 36 | printf("O megaliteros einai to %d", z); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /lesson04/efarmogi3_max3_b.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int x,y,z; 6 | int max; 7 | 8 | printf("Dwse ton 1o arithmo: "); 9 | scanf("%d", &x); 10 | 11 | printf("Dwse ton 2o arithmo: "); 12 | scanf("%d", &y); 13 | 14 | printf("Dwse ton 3o arithmo: "); 15 | scanf("%d", &z); 16 | 17 | 18 | max=x; 19 | 20 | if (y>max) 21 | max=y; 22 | 23 | if (z>max) 24 | max=z; 25 | 26 | 27 | printf("O megaliteros einai to %d", max); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /lesson04/efarmogi3_max3_c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int x; 6 | int max; 7 | 8 | printf("Dwse ton 1o arithmo: "); 9 | scanf("%d", &x); 10 | 11 | max=x; 12 | 13 | 14 | 15 | printf("Dwse ton 2o arithmo: "); 16 | scanf("%d", &x); 17 | 18 | if (x>max) 19 | max=x; 20 | 21 | 22 | 23 | printf("Dwse ton 3o arithmo: "); 24 | scanf("%d", &x); 25 | 26 | if (x>max) 27 | max=x; 28 | 29 | 30 | 31 | printf("O megaliteros einai to %d", max); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /lesson04/efarmogi4_sort3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int x,y,z; 6 | 7 | printf("Dwse ton 1o arithmo: "); 8 | scanf("%d", &x); 9 | 10 | printf("Dwse ton 2o arithmo: "); 11 | scanf("%d", &y); 12 | 13 | printf("Dwse ton 3o arithmo: "); 14 | scanf("%d", &z); 15 | 16 | 17 | if (x 2 | 3 | main() 4 | { 5 | int x; 6 | int hours, min, sec; 7 | 8 | printf("Eisagete plithos deuteroleptwn: "); 9 | scanf("%d", &x); 10 | 11 | hours=x/3600; 12 | 13 | x=x%3600; 14 | 15 | min=x/60; 16 | sec=x%60; 17 | 18 | printf("Wres: %d", hours); 19 | printf("\nLepta: %d",min); 20 | printf("\nDeuterolepta: %d",sec); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /lesson04/efarmogi6.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int zariA1, zariA2, zariB1, zariB2; 6 | 7 | printf("Dwse to apotelesma toy 1ou zariou tou 1ou paikti: "); 8 | scanf("%d",&zariA1); 9 | 10 | printf("Dwse to apotelesma toy 2ou zariou tou 1ou paikti: "); 11 | scanf("%d",&zariA2); 12 | 13 | printf("Dwse to apotelesma toy 1ou zariou tou 2ou paikti: "); 14 | scanf("%d",&zariB1); 15 | 16 | printf("Dwse to apotelesma toy 2ou zariou tou 2ou paikti: "); 17 | scanf("%d",&zariB2); 18 | 19 | 20 | 21 | if (zariA1+zariA2>zariB1+zariB2) 22 | { 23 | printf("Nikise o 1os paiktis!"); 24 | } 25 | else if (zariA1+zariA2 2 | 3 | main() 4 | { 5 | int zariA1, zariA2, zariB1, zariB2; 6 | int sum1,sum2; 7 | 8 | printf("Dwse to apotelesma toy 1ou zariou tou 1ou paikti: "); 9 | scanf("%d",&zariA1); 10 | 11 | printf("Dwse to apotelesma toy 2ou zariou tou 1ou paikti: "); 12 | scanf("%d",&zariA2); 13 | 14 | printf("Dwse to apotelesma toy 1ou zariou tou 2ou paikti: "); 15 | scanf("%d",&zariB1); 16 | 17 | printf("Dwse to apotelesma toy 2ou zariou tou 2ou paikti: "); 18 | scanf("%d",&zariB2); 19 | 20 | sum1=zariA1+zariA2; 21 | sum2=zariB1+zariB2; 22 | 23 | if (sum1>sum2) 24 | { 25 | printf("Nikise o 1os paiktis!"); 26 | } 27 | else if (sum1 2 | 3 | main() 4 | { 5 | int etos; 6 | 7 | printf("Eisagete etos: "); 8 | scanf("%d", &etos); 9 | 10 | if (etos%4==0) 11 | { 12 | if (etos%100==0 && etos%400==0) 13 | { 14 | printf("Den einai disekto!"); 15 | } 16 | else 17 | { 18 | printf("Einai disekto!"); 19 | } 20 | } 21 | else 22 | { 23 | printf("Den einai disekto!"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lesson04/if_01.c: -------------------------------------------------------------------------------- 1 | /* if_01.c: Deixnei tin xrisi tis if */ 2 | #include 3 | 4 | main() 5 | { 6 | int x; 7 | int y; 8 | 9 | printf("Dwste ton akeraio x: "); 10 | scanf("%d",&x); 11 | printf("Dwste ton akeraio y: "); 12 | scanf("%d",&y); 13 | 14 | if (xy) 24 | printf("\n%d>%d",x,y); 25 | 26 | if (x>=y) 27 | printf("\n%d>=%d",x,y); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /lesson04/if_02.c: -------------------------------------------------------------------------------- 1 | /* if_02.c: Deixnei tin xrisi tis if..else */ 2 | #include 3 | 4 | main() 5 | { 6 | int x; 7 | 8 | printf("Dwste enan akeraio: "); 9 | scanf("%d",&x); 10 | 11 | if(x%2==0) 12 | printf("O arithmos einai artios!"); 13 | else 14 | printf("O arithmos einai perittos!"); 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson04/if_03.c: -------------------------------------------------------------------------------- 1 | /* if_02.c: Deixnei tin xrisi tis if..else */ 2 | #include 3 | 4 | main() 5 | { 6 | int x; 7 | int y; 8 | 9 | printf("Dwste ton akeraio x: "); 10 | scanf("%d",&x); 11 | printf("Dwste ton akeraio y: "); 12 | scanf("%d",&y); 13 | 14 | if(xy"); 20 | 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /lesson04/logikoi.c: -------------------------------------------------------------------------------- 1 | /*logikoi.c: Anadeikniei tin leitoyrgia twn logikwn telestwn*/ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int x=1; 8 | int y=2; 9 | int z; 10 | 11 | z=(y>x) && (x 4 | 5 | main() 6 | { 7 | int x=1; 8 | int y=1; 9 | 10 | printf("%d,%d",x++,++y); 11 | printf("\n%d,%d",x++,++y); 12 | printf("\n%d,%d",x++,++y); 13 | printf("\n%d,%d",x,y); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /lesson04/prakseis.c: -------------------------------------------------------------------------------- 1 | /* prakseis.c: Anadeiknyei tin xrisi twn dimelwn mathimatikwn praksewn */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int x,y,z; 8 | int telestis; 9 | 10 | printf("\nDwste ton 1o akeraio: "); 11 | scanf("%d",&x); 12 | printf("Dwste ton 2o akeraio: "); 13 | scanf("%d",&y); 14 | printf("Dwste ton telesti\n 0 gia +\n 1 gia -\n 2 gia *\n 3 gia /\n 4 gia %%"); 15 | printf("\nEpilogi? "); 16 | scanf("%d",&telestis); 17 | 18 | if (telestis==0) 19 | { 20 | z=x+y; 21 | printf("%d+%d=%d",x,y,z); 22 | } 23 | else if (telestis==1) 24 | { 25 | z=x-y; 26 | printf("%d-%d=%d",x,y,z); 27 | } 28 | else if (telestis==2) 29 | { 30 | z=x*y; 31 | printf("%d*%d=%d",x,y,z); 32 | } 33 | else if (telestis==3) 34 | { 35 | z=x/y; 36 | printf("%d/%d=%d",x,y,z); 37 | } 38 | else if (telestis==4) 39 | { 40 | z=x%y; 41 | printf("%d%%%d=%d",x,y,z); 42 | } 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /lesson04/sxesiakoi.c: -------------------------------------------------------------------------------- 1 | /*sxesiakoi.c: Anadeikniei tin leitoyrgia twn sxesiakwn telestwn*/ 2 | #include 3 | 4 | main() 5 | { 6 | int x=2; 7 | int y=1; 8 | int z; 9 | printf("\nx=%d,y=%d",x,y); 10 | printf("\n=========",x,y); 11 | z=(x>y); 12 | printf("\nx>y:%d",z); 13 | 14 | z=(x>=y); 15 | printf("\nx>=y:%d",z); 16 | 17 | z=(x==y); 18 | printf("\nx==y:%d",z); 19 | 20 | z=(x<=y); 21 | printf("\nx<=y:%d",z); 22 | 23 | z=(x 3 | 4 | main() 5 | { 6 | int x,y,z; 7 | 8 | /* Kai i if epistrefei mia timi */ 9 | x=0; y=1; 10 | if(x 3 | 4 | int main() 5 | { 6 | int pin[3]; 7 | int sum; 8 | 9 | pin[0]=1; 10 | pin[1]=3; 11 | pin[2]=4; 12 | sum=pin[0]+pin[1]+pin[2]; 13 | printf("\n%d+%d+%d=%d",pin[0],pin[1],pin[2],sum); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lesson05/array2.c: -------------------------------------------------------------------------------- 1 | /* array.c: Aplo programma me pinaka */ 2 | #include 3 | 4 | #define SIZE 4 5 | 6 | int main() 7 | { 8 | int pin[SIZE]; 9 | int sum; 10 | 11 | pin[0]=1; 12 | pin[1]=3; 13 | pin[2]=4; 14 | pin[3]=5; 15 | 16 | pin[5]=39; 17 | 18 | sum=pin[0]+pin[1]+pin[2]+pin[3]; 19 | printf("\n%d+%d+%d+%d=%d",pin[0],pin[1],pin[2],pin[3],sum); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /lesson05/c_language_lesson_5(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson05/c_language_lesson_5(4sl).pdf -------------------------------------------------------------------------------- /lesson05/c_language_lesson_5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson05/c_language_lesson_5.pdf -------------------------------------------------------------------------------- /lesson05/complex_for.c: -------------------------------------------------------------------------------- 1 | /* complex_for.c: Deixnei to olokliromeno sintaktiko tis for */ 2 | #include 3 | 4 | main() 5 | { 6 | int i,j; 7 | 8 | for (i=0,j=0; i<5 && j<5; i++,j+=2) 9 | printf("\ni=%d,j=%d: ",i,j); 10 | 11 | } 12 | 13 | -------------------------------------------------------------------------------- /lesson05/defensive.c: -------------------------------------------------------------------------------- 1 | /* defensive.c: Amintikos Programmatismos gia to diavasma enos akeraioy */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int i; 8 | 9 | do { 10 | printf("Dwste enan akeraio apo 1 ews 100: "); 11 | scanf("%d",&i); 12 | } while (i<1 || i>100); 13 | 14 | printf("Eisagate arithmo mesa sta oria 1 ews 100: %d",i); 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson05/dowhile.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int i; 6 | 7 | i=5; 8 | 9 | do 10 | { 11 | i++; 12 | printf("\n%d",i); 13 | } while(i>3); 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /lesson05/efarmogi1.c: -------------------------------------------------------------------------------- 1 | /* ask1.c */ 2 | #include 3 | 4 | main() 5 | { 6 | int i,sum,x; 7 | sum=0; 8 | 9 | for(i=1; i<=3; i++) 10 | { 11 | printf("\nEisagete ton %d-o arithmo: ",i); 12 | scanf("%d",&x); 13 | sum=sum+x; 14 | } 15 | printf("\n\n%d",sum); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson05/efarmogi1_b.c: -------------------------------------------------------------------------------- 1 | /* ask1.c */ 2 | #include 3 | 4 | main() 5 | { 6 | int i,sum,x; 7 | sum=0; 8 | 9 | for(i=0; i<10; i++) 10 | { 11 | printf("\nEisagete ton %d-o arithmo: ",i+1); 12 | scanf("%d",&x); 13 | sum=sum+x; 14 | } 15 | printf("\n\n%d",sum); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson05/efarmogi1_c.c: -------------------------------------------------------------------------------- 1 | /* ask1.c */ 2 | #include 3 | 4 | main() 5 | { 6 | int i,prod,x; 7 | prod=1; 8 | 9 | for(i=0; i<3; i++) 10 | { 11 | printf("\nEisagete ton %d-o arithmo: ",i+1); 12 | scanf("%d",&x); 13 | prod=prod*x; 14 | } 15 | printf("\n\nTo ginomeno twn arithmwn einai: %d",prod); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson05/efarmogi2.c: -------------------------------------------------------------------------------- 1 | /* ask2.c */ 2 | #include 3 | 4 | main() 5 | { 6 | int i,j; 7 | 8 | for(i=1; i<=4; i++) 9 | { 10 | for (j=1; j<=4; j++) 11 | { 12 | printf("\n%d+%d=%d",i,j,i+j); 13 | } 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /lesson05/efarmogi3.c: -------------------------------------------------------------------------------- 1 | /* ask3.c */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int M,N; 8 | int i,j; 9 | 10 | M=10; 11 | N=20; 12 | 13 | for(i=0; i<=M; i++) 14 | { 15 | for (j=0; j<=N; j++) 16 | { 17 | printf("X"); 18 | } 19 | printf("\n"); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lesson05/efarmogi3_b.c: -------------------------------------------------------------------------------- 1 | /* ask3.c */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int M,N; 8 | int i,j; 9 | 10 | M=10; 11 | N=20; 12 | 13 | i=0; 14 | while(i<=M) 15 | { 16 | j=0; 17 | while(j<=N) 18 | { 19 | printf("X"); 20 | 21 | j++; 22 | } 23 | 24 | printf("\n"); 25 | 26 | i++; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /lesson05/efarmogi4.c: -------------------------------------------------------------------------------- 1 | /* ask4.c */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int N; 8 | int i,j; 9 | 10 | N=13; 11 | 12 | for(i=0; i<=N; i++) 13 | { 14 | for (j=i; j<=N; j++) 15 | { 16 | printf("X"); 17 | } 18 | printf("\n"); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /lesson05/efarmogi4_b.c: -------------------------------------------------------------------------------- 1 | /* ask4.c */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int N; 8 | int i,j; 9 | 10 | N=3; 11 | 12 | i=0; 13 | do 14 | { 15 | j=i; 16 | do 17 | { 18 | printf("X"); 19 | 20 | j++; 21 | } while(j<=N); 22 | 23 | 24 | printf("\n"); 25 | 26 | i++; 27 | } 28 | while(i<=N); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /lesson05/efarmogi5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SIZE 5 4 | 5 | main() 6 | { 7 | int pinakas[SIZE]; 8 | int i; 9 | int sum; 10 | 11 | /* 1. Diavasma twn arithmwn */ 12 | for (i=0; i 2 | 3 | #define SIZE 5 4 | 5 | main() 6 | { 7 | int pinakas[SIZE]; 8 | int i; 9 | int prod; 10 | 11 | /* 1. Diavasma twn arithmwn */ 12 | for (i=0; i8); 19 | } 20 | 21 | /* Ypologismos tou ginomenou twn arithmwn */ 22 | 23 | prod=1; 24 | for (i=0; i 2 | 3 | #define SIZE 20 4 | 5 | 6 | main() 7 | { 8 | int pinakas[SIZE]; 9 | int i,min; 10 | int N; 11 | 12 | /* 1.Eisagwgi tou N (1...20) me amintiko programmatismo */ 13 | 14 | do 15 | { 16 | printf("Dwse to N: "); 17 | scanf("%d",&N); 18 | } while (N<2 || N>20); 19 | 20 | /* 2.Diavasma twn N arithmwn */ 21 | 22 | for (i=0; i 2 | 3 | #define SIZE 20 4 | 5 | 6 | main() 7 | { 8 | int pinakas[SIZE]; 9 | int i,sum; 10 | int N; 11 | float mo; 12 | 13 | /* 1.Eisagwgi tou N (1...20) me amintiko programmatismo */ 14 | 15 | do 16 | { 17 | printf("Dwse to N: "); 18 | scanf("%d",&N); 19 | } while (N<2 || N>20); 20 | 21 | /* 2.Diavasma twn N arithmwn */ 22 | 23 | for (i=0; i 2 | 3 | main() 4 | { 5 | int i,x,PRO; 6 | 7 | /* Paradeigma1 */ 8 | for (i=1; i<=5; i++) 9 | printf("\nKalimera"); 10 | 11 | /* Paradeigma2 */ 12 | 13 | for (i=1; i<=10; i++) 14 | printf("\n%d",i); 15 | 16 | /* Paradeigma3 */ 17 | 18 | 19 | printf("\n\n"); 20 | 21 | PRO=16; 22 | for (i=1; i<=10; i++) 23 | { 24 | x=i*PRO; 25 | printf("\n%d*%d=%d",i,PRO,x); 26 | } 27 | 28 | /* Paradeigma4 */ 29 | 30 | 31 | printf("\n\n"); 32 | 33 | PRO=7; 34 | for (i=10; i>=1; i--) 35 | { 36 | x=i*PRO; 37 | printf("\n%d*%d=%d",i,PRO,x); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /lesson06/c_language_lesson_6(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson06/c_language_lesson_6(4sl).pdf -------------------------------------------------------------------------------- /lesson06/c_language_lesson_6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson06/c_language_lesson_6.pdf -------------------------------------------------------------------------------- /lesson06/efarmogi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int get_integer(int start, int finish); 4 | 5 | main() 6 | { 7 | int a,b,n; 8 | 9 | /* 1. Diavasma tis eisodou */ 10 | 11 | printf("Dwse to a. "); 12 | a=get_integer(1,10); 13 | printf("Dwse to b. "); 14 | b=get_integer(1,10); 15 | printf("Dwse to n. "); 16 | n=get_integer(2,5); 17 | 18 | /* 2. Ypologismos tou apotelesmatos */ 19 | 20 | printf("To apotelesma n*(a-b) einai: %d", n*(a-b)); 21 | } 22 | 23 | int get_integer(int start, int finish) 24 | { 25 | int x; 26 | 27 | do{ 28 | printf("Dwse mia timi apo %d ews %d: ", start, finish); 29 | scanf("%d",&x); 30 | } while(xfinish); 31 | 32 | return x; 33 | } 34 | -------------------------------------------------------------------------------- /lesson06/efarmogi2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int is_even(int n); 4 | int is_odd(int n); 5 | int is_square(int n); 6 | int is_cube(int n); 7 | 8 | main() 9 | { 10 | int x; 11 | 12 | printf("Eisagete ton arithmo: "); 13 | scanf("%d",&x); 14 | 15 | if (is_even(x)) 16 | printf("\nEinai Artios"); 17 | 18 | if (is_odd(x)) 19 | printf("\nEinai Perittos"); 20 | 21 | if (is_square(x)) 22 | printf("\nEinai Tetragwno Arithmou"); 23 | 24 | if (is_cube(x)) 25 | printf("\nEinai Kivos Arithmou"); 26 | } 27 | 28 | int is_even(int n) 29 | { 30 | if (n%2==0) 31 | return 1; 32 | else 33 | return 0; 34 | } 35 | 36 | int is_odd(int n) 37 | { 38 | if (n%2==1) 39 | return 1; 40 | else 41 | return 0; 42 | } 43 | 44 | int is_square(int n) 45 | { 46 | int i; 47 | 48 | for (i=1; i<=n; i++) 49 | { 50 | if (i*i==n) 51 | return 1; 52 | else if (i*i>n) 53 | return 0; 54 | } 55 | } 56 | 57 | int is_cube(int n) 58 | { 59 | int i; 60 | 61 | for (i=1; i<=n; i++) 62 | { 63 | if (i*i*i==n) 64 | return 1; 65 | else if (i*i*i>n) 66 | return 0; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lesson06/efarmogi3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int isprime(int n); 4 | 5 | main() 6 | { 7 | int i, start, finish; 8 | 9 | do { 10 | printf("Dwse tin arxi tou diastimatos: "); 11 | scanf("%d", &start); 12 | 13 | if (start<=0) 14 | printf("Lathos Eisodos. Prepei na einai >0"); 15 | } while(start<=0); 16 | 17 | 18 | do { 19 | printf("Dwse to peras tou diastimatos: "); 20 | scanf("%d", &finish); 21 | 22 | if (!(start<=finish)) 23 | printf("Lathos Eisodos. Prepei na einai >%d(start)", start); 24 | } while(!(start<=finish)); 25 | 26 | for (i=start; i<=finish; i++) 27 | if (isprime(i)) 28 | printf("\nTo %d einai prwtos", i); 29 | } 30 | 31 | int isprime(int n) 32 | { 33 | int i; 34 | int check; 35 | 36 | if (n==0||n==1) 37 | return 0; 38 | 39 | check=1; 40 | for (i=2; i<=n/2; i++) 41 | if (n%i==0) 42 | check=0; 43 | 44 | return check; 45 | } 46 | -------------------------------------------------------------------------------- /lesson06/efarmogi4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fibonacci(int n); 4 | 5 | main() 6 | { 7 | int n; 8 | 9 | printf("Dwse ton arithmo: "); 10 | scanf("%d",&n); 11 | 12 | printf("O arithmos Fibonacci-%d einai %d", n, fibonacci(n)); 13 | } 14 | 15 | int fibonacci(int n) 16 | { 17 | if (n==1 || n==2) 18 | return 1; 19 | else 20 | return fibonacci(n-1)+fibonacci(n-2); 21 | } 22 | -------------------------------------------------------------------------------- /lesson06/efarmogi5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int mkd(int a, int b); 4 | 5 | main() 6 | { 7 | int a,b; 8 | 9 | printf("Dwse ton 1o arithmo: "); 10 | scanf("%d", &a); 11 | 12 | printf("Dwse ton 2o arithmo: "); 13 | scanf("%d", &b); 14 | 15 | printf("O MKD twn dyo arithmwn einai o %d", mkd(a,b)); 16 | 17 | } 18 | 19 | int mkd(int a, int b) 20 | { 21 | 22 | if (a==b) 23 | return a; 24 | else if (a 5 | 6 | int factorial(int n); 7 | 8 | main() 9 | { 10 | int x; 11 | int res; 12 | 13 | printf("Dwste ton fysiko: "); 14 | scanf("%d",&x); 15 | 16 | res=factorial(x); 17 | 18 | printf("%d!=%d",x,res); 19 | } 20 | 21 | int factorial(int n) 22 | { 23 | int y; 24 | 25 | if (n==1) 26 | return 1; 27 | else 28 | { 29 | y=factorial(n-1); 30 | return n*y; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /lesson06/orismata.c: -------------------------------------------------------------------------------- 1 | /* orismata.c: Anadeikniei pos pairname orismata se sinartiseis */ 2 | 3 | #include 4 | 5 | int square(int x); 6 | 7 | main() 8 | { 9 | int a=5; 10 | int b=10; 11 | int teta,tetb,sum; 12 | 13 | teta=square(a); 14 | tetb=square(b); 15 | sum=teta+tetb; 16 | printf("%d^2 + %d^2 = %d",a,b,sum); 17 | } 18 | 19 | int square(int x) 20 | { 21 | int y; 22 | 23 | y=x*x; 24 | 25 | return y; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lesson06/variables.c: -------------------------------------------------------------------------------- 1 | /* variables.c: Deixnei ton diaxorismo 2 | katholikwn-topikwn metablitwn*/ 3 | 4 | #include 5 | 6 | void f1(); 7 | void f2(); 8 | 9 | int x; /* Katholiki metavliti: Tin vlepoun 10 | oloi */ 11 | 12 | main() 13 | { 14 | int a=0; /*Topiki metabliti stin main */ 15 | 16 | x=5; 17 | printf("\nmain: a=%d,x=%d",a,x); 18 | f1(); 19 | printf("\nmain: a=%d,x=%d",a,x); 20 | f2(); 21 | printf("\nmain: a=%d,x=%d",a,x); 22 | } 23 | 24 | void f1() 25 | { 26 | int a=2, x=0; /*Topikes metavlites 27 | tis f1 */ 28 | /* Exoyme diplo onoma stin x. 29 | Epikratei to topiko onoma */ 30 | 31 | printf("\nf1: a=%d,x=%d",a,x); 32 | } 33 | 34 | void f2() 35 | { 36 | int a=8; /*Topikes metavlites tis 37 | f2 */ 38 | x=7; /* Anaferetai stin katholiki 39 | x */ 40 | 41 | printf("\nf2: a=%d,x=%d",a,x); 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /lesson07/array.c: -------------------------------------------------------------------------------- 1 | /* array.c: Aplo programma me pinaka */ 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int pin[3]; 8 | int sum; 9 | 10 | pin[0]=1; 11 | pin[1]=3; 12 | pin[2]=4; 13 | sum=pin[0]+pin[1]+pin[2]; 14 | printf("\n%d+%d+%d=%d",pin[0],pin[1],pin[2],sum); 15 | } 16 | -------------------------------------------------------------------------------- /lesson07/array2.c: -------------------------------------------------------------------------------- 1 | /* array2.c: Aplo programma me pinaka */ 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int pin[3] = {1,3,4}; 8 | int sum; 9 | 10 | sum=pin[0]+pin[1]+pin[2]; 11 | printf("\n%d+%d+%d=%d",pin[0],pin[1],pin[2],sum); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lesson07/c_language_lesson_7_arrays(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson07/c_language_lesson_7_arrays(4sl).pdf -------------------------------------------------------------------------------- /lesson07/c_language_lesson_7_arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson07/c_language_lesson_7_arrays.pdf -------------------------------------------------------------------------------- /lesson07/efarmogi1_array1d.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define SIZE 100 6 | 7 | main() 8 | { 9 | int pinakas[SIZE]; 10 | int i,N; 11 | 12 | /* 1. Diavasma tis diastasis tou pinaka */ 13 | 14 | do{ 15 | printf("Dwse to plithos twn stoixeiwn tou pinaka(20..100): "); 16 | scanf("%d", &N); 17 | } while (N<20 || N>100); 18 | 19 | /* 2. Arxikopoiisi tou Pinaka */ 20 | srand(time(NULL)); 21 | 22 | for (i=0; i 2 | #include 3 | #include 4 | 5 | #define M 5 6 | #define N 8 7 | 8 | main() 9 | { 10 | int pinakas[M][N]; 11 | int i,j; 12 | 13 | /* 1. Arxikopoiisi me tyxaious arithmous */ 14 | srand(time(NULL)); 15 | 16 | for (i=0; i 2 | #include 3 | #include 4 | 5 | #define SIZE1 100 6 | #define SIZE2 200 7 | 8 | main() 9 | { 10 | int pinakas[SIZE1][SIZE2]; 11 | int M,N; 12 | int i,j; 13 | 14 | /* 1. Diavasma twn diastasewn */ 15 | 16 | do{ 17 | printf("Dwse to plithos twn grammwn tou pinaka(10..100): "); 18 | scanf("%d", &M); 19 | } while (M<10 || M>100); 20 | 21 | do{ 22 | printf("Dwse to plithos twn stilwn tou pinaka(8..200): "); 23 | scanf("%d", &N); 24 | } while (N<8 || N>200); 25 | 26 | /* 2. Arxikopoiisi me tyxaious arithmous */ 27 | srand(time(NULL)); 28 | 29 | for (i=0; i 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | int hidden; 8 | int x; 9 | 10 | /* 1. arxikopoiisi tou krymmenou arithmou */ 11 | srand(time(NULL)); 12 | hidden=1+rand()%100; 13 | 14 | /* 2.O xristis mantevei ton arithmo */ 15 | 16 | do { 17 | 18 | printf("\n\nMantepse ton arithmo: "); 19 | scanf("%d", &x); 20 | 21 | if (x==hidden) 22 | { 23 | printf("Mpravo! Ton mantepses swsta! "); 24 | } 25 | else if (x>hidden) 26 | { 27 | printf("Lathos! Prepei na valeis mikrotero!"); 28 | } 29 | else 30 | { 31 | printf("Lathos! Prepei na valeis megalitero!"); 32 | } 33 | 34 | } while (x!=hidden); 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /lesson07/random.c: -------------------------------------------------------------------------------- 1 | /* random.c: Typwnei 10 tyxaioys akeraioys sto diastima 0..99 */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | main() 8 | { 9 | int x,i; 10 | 11 | srand(time(NULL)); 12 | 13 | for (i=0; i<10; i++) 14 | { 15 | x=rand()%100; 16 | printf("\n%d",x); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lesson08/array_ref.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void f(int *p, int n); 4 | 5 | main() 6 | { 7 | int pin[100]; 8 | int i; 9 | 10 | for (i=0; i<100; i++) 11 | pin[i]=i; 12 | 13 | 14 | for (i=0; i<100; i++) 15 | printf("%d ", pin[i]); 16 | 17 | 18 | f(pin,100); 19 | 20 | printf("\n\n"); 21 | for (i=0; i<100; i++) 22 | printf("%d ", pin[i]); 23 | 24 | } 25 | 26 | 27 | void f(int *p, int n) 28 | { 29 | int i; 30 | 31 | for (i=0; i 3 | 4 | void swap(int *ptrA, int *ptrB); 5 | 6 | main() 7 | { 8 | int a=5,b=10; 9 | printf("\nMain: a=%d,b=%d",a,b); 10 | swap(&a,&b); 11 | printf("\nMain: a=%d,b=%d",a,b); 12 | } 13 | 14 | void swap(int *ptrA, int *ptrB) 15 | { 16 | int k; 17 | k=*ptrA; 18 | *ptrA=*ptrB; 19 | *ptrB=k; 20 | printf("\nSwap: a=%d,b=%d",*ptrA,*ptrB); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lesson08/byvalue.c: -------------------------------------------------------------------------------- 1 | /*byvalue.c: Perasma orismatwn mesw timis */ 2 | #include 3 | 4 | void swap(int a,int b); 5 | 6 | main() 7 | { 8 | int a=5,b=10; 9 | printf("\nMain: a=%d,b=%d",a,b); 10 | swap(a,b); 11 | printf("\nMain: a=%d,b=%d",a,b); 12 | } 13 | 14 | void swap(int a, int b) 15 | { 16 | int k; 17 | k=a; 18 | a=b; 19 | b=k; 20 | printf("\nSwap: a=%d,b=%d",a,b); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lesson08/c_language_lesson_8_pointers(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson08/c_language_lesson_8_pointers(4sl).pdf -------------------------------------------------------------------------------- /lesson08/c_language_lesson_8_pointers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson08/c_language_lesson_8_pointers.pdf -------------------------------------------------------------------------------- /lesson08/efarmogi1_rizes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int rizes(float a, float b, float c, float *x1, float *x2); 5 | 6 | main() 7 | { 8 | float a,b,c,riza1,riza2; 9 | int plithos; 10 | 11 | /* 1. Diavasma tis eisodou */ 12 | 13 | printf("Dwse to a: "); 14 | scanf("%f",&a); 15 | 16 | printf("Dwse to b: "); 17 | scanf("%f",&b); 18 | 19 | printf("Dwse to c: "); 20 | scanf("%f",&c); 21 | 22 | /* 2. Ypologismos rizwn */ 23 | plithos=rizes(a,b,c,&riza1, &riza2); 24 | 25 | /* 3. Ektypwsi tou apotelesmatos */ 26 | 27 | if (plithos==0) 28 | printf("Den exei pragmatikes rizes"); 29 | else if (plithos==1) 30 | printf("Exei dipli riza tin %f", riza1); 31 | else 32 | printf("Exei rizes: %f kai %f", riza1, riza2); 33 | 34 | } 35 | 36 | int rizes(float a, float b, float c, float *x1, float *x2) 37 | { 38 | float D; 39 | 40 | D=b*b-4*a*c; 41 | 42 | if (D<0) 43 | return 0; 44 | else if (D==0) 45 | { 46 | *x1 = -b/(2*a); 47 | return 1; 48 | } 49 | else 50 | { 51 | *x1=(-b+sqrt(D))/(2*a); 52 | *x2=(-b-sqrt(D))/(2*a); 53 | return 2; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lesson08/efarmogi2-5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define SIZE 1000 6 | 7 | void init_array(int *pinakas, int n, int a, int b); 8 | void print_array(int *pinakas, int n); 9 | int max_array(int *pinakas, int n); 10 | 11 | main() 12 | { 13 | int array[SIZE],N; 14 | int choice,a,b; 15 | 16 | choice=1; 17 | while (choice!=5) 18 | { 19 | printf("\n\nMENOY EPILOGWN"); 20 | printf("\n--------------"); 21 | printf("\n1-Eisagwgi tou megethous tou pinaka"); 22 | printf("\n2-Arxikopoiisi Pinaka"); 23 | printf("\n3-Ypologismos tou megistou"); 24 | printf("\n4-Ektypwsi tou pinaka"); 25 | printf("\n5-Eksodos"); 26 | printf("\n Epilogi? "); 27 | scanf("%d", &choice); 28 | 29 | if (choice==1) 30 | { 31 | printf("Dwse to megethos tou pinaka: "); 32 | scanf("%d", &N); 33 | } 34 | else if (choice==2) 35 | { 36 | printf("Dwse tin arxi tou diastimatos tvn tyxaiwn: "); 37 | scanf("%d",&a); 38 | printf("Dwse to peras tou diastimatos tvn tyxaiwn: "); 39 | scanf("%d",&b); 40 | init_array(array, N, a, b); 41 | } 42 | else if (choice==3) 43 | { 44 | printf("O megistos einai: %d", max_array(array, N)); 45 | } 46 | else if (choice==4) 47 | { 48 | print_array(array, N); 49 | } 50 | else if (choice==5) 51 | { 52 | printf("Bye Bye"); 53 | } 54 | 55 | } 56 | 57 | 58 | 59 | } 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | void init_array(int *pinakas, int n, int a, int b) 69 | { 70 | int i; 71 | 72 | srand(time(NULL)); 73 | 74 | for (i=0; imax) 97 | max=pinakas[i]; 98 | } 99 | 100 | return max; 101 | } 102 | -------------------------------------------------------------------------------- /lesson08/matrix_pointers.c: -------------------------------------------------------------------------------- 1 | /* matrix_pointers.c: Deixnei oti oi theseis mnimis enos pinaka einai diadoxikes */ 2 | 3 | #include 4 | 5 | #define N 4 6 | 7 | main() 8 | { 9 | int pin[N]; 10 | int i; 11 | 12 | for (i=0; i 2 | 3 | main() 4 | { 5 | int x=5; 6 | int *p; 7 | 8 | p=NULL; 9 | 10 | printf("%d",NULL); 11 | 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /lesson08/pointer_calc.c: -------------------------------------------------------------------------------- 1 | /* pointer_calc.c: Pws exoume prosvasi sta stoixeia enos pinaka mesw deikti */ 2 | 3 | #include 4 | 5 | #define N 10 6 | 7 | main() 8 | { 9 | int pin[N]; 10 | int i; 11 | int *ptr; 12 | 13 | ptr=pin; 14 | for (i=0; i 4 | 5 | main() 6 | { 7 | int x; 8 | int *ptr; 9 | 10 | ptr=&x; 11 | 12 | x=5; 13 | printf("x=%d\t *ptr=%d\t &x=%d\t ptr=%d",x,*ptr,&x,ptr); 14 | *ptr=8; 15 | printf("\nx=%d\t *ptr=%d\t &x=%d\t ptr=%d",x,*ptr,&x,ptr); 16 | x=9; 17 | printf("\nx=%d\t *ptr=%d\t &x=%d\t ptr=%d",x,*ptr,&x,ptr); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lesson09/advanced.c: -------------------------------------------------------------------------------- 1 | /* advanced.c: Proxwrimeno paradeigma stin printf */ 2 | #include 3 | 4 | int main() 5 | { 6 | printf ("Simplirwsi me kena: |%10d| \n", 1980); 7 | printf ("Simplirwsi me midenika: |%010d| \n", 1980); 8 | printf ("Morfes arithmou: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100); 9 | printf ("Pragmatikoi: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416); 10 | printf ("Me to asteraki: %*d \n", 5, 10); 11 | } 12 | -------------------------------------------------------------------------------- /lesson09/c_language_lesson_9_print_scan(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson09/c_language_lesson_9_print_scan(4sl).pdf -------------------------------------------------------------------------------- /lesson09/c_language_lesson_9_print_scan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson09/c_language_lesson_9_print_scan.pdf -------------------------------------------------------------------------------- /lesson09/dekadika.c: -------------------------------------------------------------------------------- 1 | /*width_precision.c: Deixnei tin epirroi ston prosdioristi twn width+precision */ 2 | #include 3 | 4 | main() 5 | { 6 | float f=10.0/7.0; 7 | int i,num; 8 | 9 | printf("\nPragmatikoi Arithmoi: "); 10 | printf("\n%8.3f", f); 11 | printf("\n%8.4f", f); 12 | printf("\n%8.5f", f); 13 | printf("\n%8.6f", f); 14 | 15 | printf("\n\nAkeraioi Arithmoi: "); 16 | num=1; 17 | for (i=1; i<=8; i++) 18 | { 19 | printf("\n|%-10d|%10d|",num,num); 20 | num*=10; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lesson09/efarmogi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print(); 4 | void eisagogi_pinaka(); 5 | 6 | main() 7 | { 8 | int choice; 9 | int number; 10 | float fNum; 11 | 12 | 13 | do{ 14 | printf("Dwse enan arithmo apo 1 ews to 4: "); 15 | scanf("%d",&choice); 16 | } while (choice<1 || choice>4); 17 | 18 | if (choice==1) 19 | { 20 | printf("Dwse enan akeraio arithmo: "); 21 | scanf("%d",&number); 22 | printf("\nTo tetragwno tou einai: %d",number*number); 23 | } 24 | else if (choice==2) 25 | { 26 | print(); 27 | } 28 | else if (choice==3) 29 | { 30 | printf("Dwse enan pragmatiko arithmo:"); 31 | scanf("%f",&fNum); 32 | printf("To 1/4 tou arithmou pou evales einai: %.4f",fNum); 33 | } 34 | else if (choice==4) 35 | { 36 | eisagogi_pinaka(); 37 | } 38 | 39 | 40 | } 41 | 42 | void print() 43 | { 44 | int i,N; 45 | 46 | printf("Dwse to N: "); 47 | scanf("%d",&N); 48 | 49 | for (i=0; i 2 | 3 | main() 4 | { 5 | int i,j; 6 | 7 | for (i=1; i<=5; i++) 8 | { 9 | for (j=1; j<=i; j++) 10 | printf("*"); 11 | for (j=1; j<=5-i; j++) 12 | printf(" "); 13 | 14 | for (j=1; j<=5-i; j++) 15 | printf(" "); 16 | for (j=1; j<=i; j++) 17 | printf("*"); 18 | printf("\n"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lesson09/efarmogi3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int N=9; 6 | int i,j,k; 7 | 8 | for (i=N; i>=1; i--) 9 | { 10 | for (k=1; k<=3; k++) 11 | { 12 | for (j=1; j<=i; j++) 13 | printf("%d",j); 14 | for (j=1; j<=N-i; j++) 15 | printf(" "); 16 | 17 | for (j=1; j<=N-i; j++) 18 | printf(" "); 19 | for (j=i; j>=1; j--) 20 | printf("%d",j); 21 | } 22 | 23 | printf("\n"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lesson09/efarmogi3_dies.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int N=5; 6 | int i,j,k; 7 | int x1,x2; 8 | 9 | x1=12345; 10 | x2=54321; 11 | 12 | for (i=N; i>=1; i--) 13 | { 14 | for (k=1; k<=3; k++) 15 | { 16 | printf("%d",x1); 17 | for (j=1; j<=N-i; j++) 18 | printf(" "); 19 | 20 | for (j=1; j<=N-i; j++) 21 | printf(" "); 22 | printf("%d",x2); 23 | } 24 | x1=x1/10; 25 | x2=x2/10; 26 | 27 | printf("\n"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lesson09/prosd.c: -------------------------------------------------------------------------------- 1 | /* prosd.c: Anadeikniei tin xrisi twn prosdioristwn */ 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int x,y; 8 | float a,b; 9 | 10 | x=1; 11 | y=2; 12 | a=1.0; 13 | b=1.0; 14 | printf("\nAkeraioi Arithmoi: (%d+%d)/2=%d",x,y,(x+y)/2); 15 | printf("\nPragmatikoi Arithmoi: (%f+%f)/2=%f",a,b,(a+b)/3); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson09/special.c: -------------------------------------------------------------------------------- 1 | /* special.c: Anadeikniei tin xrisi twn xaraktirwn 2 | diafigis */ 3 | 4 | #include 5 | 6 | main() 7 | { 8 | printf("\n\t\tANAFORA"); 9 | printf("\n ---------------------------------"); 10 | printf("\n\tAtomo\t\tAmoibi "); 11 | printf("\n ---------------------------------"); 12 | printf("\n \tGiorgos\t\t 100"); 13 | printf("\n \tKostas\t\t 200"); 14 | printf("\n \tEleni\t\t 150"); 15 | printf("\n ---------------------------------"); 16 | 17 | printf("\n\aBeep.\n\aBeep.\n\aBeep."); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lesson09/width_precision.c: -------------------------------------------------------------------------------- 1 | /*width_precision.c: Deixnei tin epirroi ston prosdioristi twn width+precision */ 2 | #include 3 | 4 | main() 5 | { 6 | float f=10.0/7.0; 7 | int i,num; 8 | 9 | printf("\nPragmatikoi Arithmoi: "); 10 | printf("\n%8.3f", f); 11 | printf("\n%8.4f", f); 12 | printf("\n%8.5f", f); 13 | printf("\n%8.6f", f); 14 | 15 | printf("\n\nAkeraioi Arithmoi: "); 16 | num=1; 17 | for (i=1; i<=8; i++) 18 | { 19 | printf("\n|%-10d|%10d|",num,num); 20 | num*=10; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lesson10/c_language_lesson_10_ascii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson10/c_language_lesson_10_ascii.pdf -------------------------------------------------------------------------------- /lesson10/c_language_lesson_10_strings(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson10/c_language_lesson_10_strings(4sl).pdf -------------------------------------------------------------------------------- /lesson10/c_language_lesson_10_strings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson10/c_language_lesson_10_strings.pdf -------------------------------------------------------------------------------- /lesson10/char.c: -------------------------------------------------------------------------------- 1 | /* char.c */ 2 | #include 3 | 4 | main() 5 | { 6 | char c; 7 | 8 | for (c=80; c<=100; c++) 9 | { 10 | printf("\nO xaraktiras %d einai %c",c,c); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /lesson10/efarmogi1_mystrlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SIZE 1000 4 | 5 | int mystrlen(char *s); 6 | 7 | main() 8 | { 9 | char str[SIZE]; 10 | 11 | printf("Dwse tin simvoloseira: "); 12 | gets(str); 13 | 14 | printf("To mikos tis simvoloseiras einai %d", mystrlen(str)); 15 | } 16 | 17 | int mystrlen(char *s) 18 | { 19 | int cnt=0; 20 | 21 | while(s[cnt]!='\0') 22 | { 23 | cnt++; 24 | } 25 | 26 | return cnt; 27 | } 28 | -------------------------------------------------------------------------------- /lesson10/efarmogi2_mystrcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 1000 3 | 4 | char *mystrcpy(char *dest, char *src); 5 | 6 | main() 7 | { 8 | char str1[SIZE], str2[SIZE], str3[SIZE]; 9 | int choice; 10 | 11 | printf("Dwse ti 1i simvoloseira: "); 12 | gets(str1); 13 | 14 | printf("Dwse ti 2i simvoloseira: "); 15 | gets(str2); 16 | 17 | printf("Epelekse mia simvoloseira (1 i 2): "); 18 | scanf("%d", &choice); 19 | 20 | if (choice==1) 21 | mystrcpy(str3,str1); 22 | else if (choice==2) 23 | mystrcpy(str3,str2); 24 | 25 | printf("\n\n1: %s\n2: %s\n3: %s", str1,str2,str3); 26 | } 27 | 28 | char *mystrcpy(char *dest, char *src) 29 | { 30 | int i; 31 | 32 | while (1) 33 | { 34 | dest[i]=src[i]; 35 | if (src[i]=='\0') 36 | break; 37 | i++; 38 | } 39 | 40 | return dest; 41 | } 42 | -------------------------------------------------------------------------------- /lesson10/efarmogi3_capitalize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 150 3 | 4 | 5 | main() 6 | { 7 | char str[SIZE]; 8 | int i; 9 | 10 | printf("Dwse ti simvoloseira: "); 11 | gets(str); 12 | 13 | i=0; 14 | 15 | while (str[i]!='\0') 16 | { 17 | if (str[i]>='a' && str[i]<='z') 18 | { 19 | str[i]=str[i]-32; 20 | } 21 | 22 | i++; 23 | } 24 | 25 | printf("Nea symvoloseira: %s", str); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /lesson10/efarmogi4_ascii_table.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define M 20 4 | #define N 4 5 | 6 | main() 7 | { 8 | int i; 9 | 10 | /*1i grammi*/ 11 | printf("\n\n\n\n\t\t%c",201); 12 | for (i=1; i<=M; i++) 13 | printf("%c", 205); 14 | printf("%c",187); 15 | 16 | /*2i grammi*/ 17 | printf("\n\t\t%c",186); 18 | for (i=1; i<=N; i++) 19 | printf(" ", 205); 20 | printf("Hello World!"); 21 | for (i=1; i<=N; i++) 22 | printf(" ", 205); 23 | printf("%c",186); 24 | 25 | /*3i grammi */ 26 | printf("\n\t\t%c",200); 27 | for (i=1; i<=M; i++) 28 | printf("%c", 205); 29 | printf("%c\n\n\n\n",188); 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /lesson10/efarmogi5_string_compare.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SIZE 150 5 | 6 | #define TRUE 1 7 | #define FALSE 0 8 | 9 | int check_string(char *str); 10 | int mystrcmp(char *str1, char *str2); 11 | 12 | main() 13 | { 14 | char str1[SIZE], str2[SIZE]; 15 | int x; 16 | 17 | printf("Dwse tin 1i simvoloseira: "); 18 | gets(str1); 19 | if (check_string(str1)==FALSE) 20 | { 21 | printf("Lathos eisodos!"); 22 | exit(0); 23 | } 24 | 25 | printf("Dwse tin 2i simvoloseira: "); 26 | gets(str2); 27 | if (check_string(str2)==FALSE) 28 | { 29 | printf("Lathos eisodos!"); 30 | exit(0); 31 | } 32 | 33 | x=mystrcmp(str1,str2); 34 | 35 | if (x==-1) 36 | printf("\nIsxyei: %s < %s", str1, str2); 37 | else if (x==0) 38 | printf("\nIsxyei: %s = %s", str1, str2); 39 | else 40 | printf("\nIsxyei: %s < %s", str2, str1); 41 | } 42 | 43 | int check_string(char *str) 44 | { 45 | int i; 46 | 47 | i=0; 48 | while(str[i]!='\0') 49 | { 50 | if (!(str[i]>='a' && str[i]<='z')) 51 | { 52 | return FALSE; 53 | } 54 | 55 | i++; 56 | } 57 | 58 | return TRUE; 59 | } 60 | 61 | /* Epistrefei: 62 | -1: an str1 < str2 63 | 0: an str1==str2 64 | 1: an str1 > str2 65 | */ 66 | int mystrcmp(char *str1, char *str2) 67 | { 68 | int i; 69 | 70 | i=0; 71 | while(1) 72 | { 73 | if (str1[i]=='\0' && str2[i]!='\0') 74 | return -1; 75 | else if (str2[i]=='\0' && str1[i]!='\0') 76 | return 1; 77 | else if (str1[i]=='\0' && str1[i]=='\0') 78 | return 0; 79 | 80 | 81 | if (str1[i]str2[i]) 84 | return 1; 85 | 86 | i++; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /lesson10/string.c: -------------------------------------------------------------------------------- 1 | /* string.c: Deixnei tin xrisi tis scanf kai tis printf me simvoloseires */ 2 | #include 3 | 4 | main() 5 | { 6 | char string[80]; 7 | 8 | printf("Dwste mia simboloseira: "); 9 | scanf("%s",string); 10 | 11 | printf("Pliktrologisate tin simvoloseira: %s",string); 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /lesson10/string2.c: -------------------------------------------------------------------------------- 1 | /* string.c: Deixnei tin xrisi tis scanf kai tis printf me simvoloseires */ 2 | #include 3 | 4 | main() 5 | { 6 | char string[80]; 7 | 8 | printf("Dwste mia simboloseira: "); 9 | gets(string); 10 | 11 | printf("Pliktrologisate tin simvoloseira "); 12 | puts(string); 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lesson11/break.c: -------------------------------------------------------------------------------- 1 | /* break.c: Deixnei tin xrisi tis break */ 2 | 3 | #include 4 | 5 | #define N 5 6 | 7 | main() 8 | { 9 | int i; 10 | int A[N]= {5, 3, 2, 4, 8 }; // Pinakas dedomenwn 11 | int x=2; // Pros anazitisi stoixeio 12 | 13 | /* Psaxnoume gia to stoixeio x ston pinaka A */ 14 | for (i=0; i 4 | 5 | main() 6 | { 7 | int i; 8 | 9 | for (i=0; i<10; i++) 10 | { 11 | printf("\nArithmos: %d",i); 12 | if (i%2==0) 13 | continue; 14 | printf(", kai to tetragono tou: %d",i*i); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson11/efarmogi1_menu.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print(); 4 | void eisagogi_pinaka(); 5 | 6 | main() 7 | { 8 | int choice; 9 | int number; 10 | float fNum; 11 | 12 | 13 | do{ 14 | printf("Dwse enan arithmo apo 1 ews to 4: "); 15 | scanf("%d",&choice); 16 | } while (choice<1 || choice>4); 17 | 18 | 19 | switch(choice) 20 | { 21 | case 1: 22 | printf("Dwse enan akeraio arithmo: "); 23 | scanf("%d",&number); 24 | printf("\nTo tetragwno tou einai: %d",number*number); 25 | break; 26 | case 2: 27 | print(); 28 | break; 29 | case 3: 30 | printf("Dwse enan pragmatiko arithmo:"); 31 | scanf("%f",&fNum); 32 | printf("To 1/4 tou arithmou pou evales einai: %.4f",fNum); 33 | break; 34 | case 4: 35 | eisagogi_pinaka(); 36 | break; 37 | default: 38 | printf("Lathos eisodos! "); 39 | } 40 | 41 | 42 | 43 | } 44 | 45 | void print() 46 | { 47 | int i,N; 48 | 49 | printf("Dwse to N: "); 50 | scanf("%d",&N); 51 | 52 | for (i=0; i 2 | #include 3 | #include 4 | 5 | #define SIZE 1000 6 | 7 | void init_array(int *pinakas, int n, int a, int b); 8 | void print_array(int *pinakas, int n); 9 | int max_array(int *pinakas, int n); 10 | 11 | main() 12 | { 13 | int array[SIZE],N; 14 | int choice,a,b; 15 | 16 | while (1) 17 | { 18 | system("cls"); 19 | printf("\n\nMENOY EPILOGWN"); 20 | printf("\n--------------"); 21 | printf("\n1-Eisagwgi tou megethous tou pinaka"); 22 | printf("\n2-Arxikopoiisi Pinaka"); 23 | printf("\n3-Ypologismos tou megistou"); 24 | printf("\n4-Ektypwsi tou pinaka"); 25 | printf("\n5-Eksodos"); 26 | printf("\n Epilogi? "); 27 | scanf("%d", &choice); 28 | 29 | switch(choice) 30 | { 31 | case 1: 32 | printf("Dwse to megethos tou pinaka: "); 33 | scanf("%d", &N); 34 | break; 35 | case 2: 36 | printf("Dwse tin arxi tou diastimatos tvn tyxaiwn: "); 37 | scanf("%d",&a); 38 | printf("Dwse to peras tou diastimatos tvn tyxaiwn: "); 39 | scanf("%d",&b); 40 | init_array(array, N, a, b); 41 | break; 42 | case 3: 43 | printf("O megistos einai: %d", max_array(array, N)); 44 | break; 45 | case 4: 46 | print_array(array, N); 47 | break; 48 | case 5: 49 | printf("Bye Bye"); 50 | exit(0); 51 | default: 52 | printf("Lathos eisodos! "); 53 | } 54 | 55 | printf("\n\n"); 56 | system("pause"); 57 | 58 | } 59 | 60 | 61 | 62 | } 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | void init_array(int *pinakas, int n, int a, int b) 72 | { 73 | int i; 74 | 75 | srand(time(NULL)); 76 | 77 | for (i=0; imax) 100 | max=pinakas[i]; 101 | } 102 | 103 | return max; 104 | } 105 | -------------------------------------------------------------------------------- /lesson11/goto.c: -------------------------------------------------------------------------------- 1 | /* goto.c: Deixnei tin xrisi tis goto */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int i=0; 8 | 9 | label: // To onoma tis etiketas 10 | printf("\ni=%d",i); 11 | 12 | if (i<5) 13 | { 14 | i++; 15 | goto label; 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /lesson11/wrong_switch.c: -------------------------------------------------------------------------------- 1 | /* wrong_switch.c: Deixnei mia kaki xrisi tis switch xwris ta aparaitita break */ 2 | #include 3 | main() 4 | { 5 | int x; 6 | 7 | scanf("%d",&x); 8 | 9 | switch(x) 10 | { 11 | case 1: 12 | printf("\nEisagate 1"); 13 | case 2: 14 | printf("\nEisagate 2"); 15 | case 3: 16 | printf("\nEisagate 3"); 17 | case 4: 18 | printf("\nEisagate 4"); 19 | default: 20 | printf("\nEisagate arithmo >=5"); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /lesson12/askisi2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define SIZE 20 6 | 7 | main() 8 | { 9 | int st_array[SIZE][SIZE]; 10 | int **dyn_array; 11 | int N; 12 | int i,j; 13 | 14 | srand(time(0)); 15 | 16 | /* Statikos Pinakas */ 17 | 18 | do { 19 | printf("Dwse N: "); 20 | scanf("%d", &N); 21 | 22 | if (N<5 || N>20) 23 | printf("Lathos Eisodos (5..20). "); 24 | } while (N<5 || N>20); 25 | 26 | for (i=0; i 2 | #include 3 | #include 4 | 5 | #define SIZE 20 6 | 7 | main() 8 | { 9 | int st_array[SIZE][SIZE]; 10 | int **dyn_array; 11 | int N; 12 | int i,j; 13 | 14 | srand(time(0)); 15 | 16 | /* Statikos Pinakas */ 17 | 18 | do { 19 | printf("Dwse N: "); 20 | scanf("%d", &N); 21 | 22 | if (N<5 || N>20) 23 | printf("Lathos Eisodos (5..20). "); 24 | } while (N<5 || N>20); 25 | 26 | for (i=0; i 2 | #include 3 | 4 | #define N 10 5 | #define SIZE 512 6 | 7 | #define TRUE 1 8 | #define FALSE 0 9 | 10 | int check_string(char *str); 11 | int mystrlen(char *s); 12 | char *mystrcpy(char *dest, char *src); 13 | 14 | 15 | main() 16 | { 17 | char *pinakas[N]; 18 | char buffer[SIZE]; 19 | int i, len; 20 | 21 | for (i=0; i='a' && str[i]<='z')) 59 | { 60 | return FALSE; 61 | } 62 | 63 | i++; 64 | } 65 | 66 | return TRUE; 67 | } 68 | 69 | int mystrlen(char *s) 70 | { 71 | int cnt=0; 72 | 73 | while(s[cnt]!='\0') 74 | { 75 | cnt++; 76 | } 77 | 78 | return cnt; 79 | } 80 | 81 | char *mystrcpy(char *dest, char *src) 82 | { 83 | int i=0; 84 | 85 | while (1) 86 | { 87 | dest[i]=src[i]; 88 | if (src[i]=='\0') 89 | break; 90 | i++; 91 | } 92 | 93 | return dest; 94 | } 95 | -------------------------------------------------------------------------------- /lesson12/c_language_lesson_12_malloc(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson12/c_language_lesson_12_malloc(4sl).pdf -------------------------------------------------------------------------------- /lesson12/c_language_lesson_12_malloc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson12/c_language_lesson_12_malloc.pdf -------------------------------------------------------------------------------- /lesson12/efarmogi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() 5 | { 6 | double **p; //Dilwsi diplou deikti-pinaka 7 | int i,j,M,N; 8 | 9 | /* Diavasma Diastasewn Pinaka */ 10 | printf("Dwse to plithos twn grammwn tou pinaka: "); 11 | scanf("%d",&M); 12 | printf("Dwse to plithos twn stilwn tou pinaka: "); 13 | scanf("%d",&N); 14 | 15 | /* Dynamiki Desmeysi mnimis */ 16 | p=malloc(sizeof(double*)*M); 17 | if (!p) 18 | { 19 | printf("Adynamia desmeusis mnimis"); 20 | exit(0); 21 | } 22 | for (i=0; i 3 | #include 4 | 5 | main() 6 | { 7 | int *p; //Dilwsi deikti 8 | int i,N; 9 | 10 | /* Diavasma Diastasis Pinaka */ 11 | printf("Dwse ti diastasi tou pinaka: "); 12 | scanf("%d",&N); 13 | 14 | /* Dynamiki Desmeysi mnimis */ 15 | p=malloc(sizeof(int)*N); 16 | if (!p) 17 | { 18 | printf("Adynamia desmeusis mnimis"); 19 | exit(0); 20 | } 21 | 22 | /* Kapoios Ypologismos ston pinaka */ 23 | for (i=0; i 3 | #include 4 | 5 | main() 6 | { 7 | int **p; //Dilwsi diplou deikti-pinaka 8 | int i,j,M,N; 9 | 10 | /* Diavasma Diastasewn Pinaka */ 11 | printf("Dwse to plithos twn grammwn tou pinaka: "); 12 | scanf("%d",&M); 13 | printf("Dwse to plithos twn stilwn tou pinaka: "); 14 | scanf("%d",&N); 15 | 16 | /* Dynamiki Desmeysi mnimis */ 17 | p=malloc(sizeof(int*)*M); 18 | if (!p) 19 | { 20 | printf("Adynamia desmeusis mnimis"); 21 | exit(0); 22 | } 23 | for (i=0; i 3 | #include 4 | 5 | main() 6 | { 7 | int *p; 8 | 9 | p=malloc(sizeof(int)); 10 | if (!p) 11 | { 12 | printf("Adynamia desmeusis mnimis"); 13 | exit(0); 14 | } 15 | 16 | printf("Dwse enan akeraio arithmo: "); 17 | scanf("%d",p); 18 | printf("Pliktrologisate %d",*p); 19 | 20 | free(p); 21 | } 22 | -------------------------------------------------------------------------------- /lesson13/c_language_lesson_13_structs(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson13/c_language_lesson_13_structs(4sl).pdf -------------------------------------------------------------------------------- /lesson13/c_language_lesson_13_structs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson13/c_language_lesson_13_structs.pdf -------------------------------------------------------------------------------- /lesson13/efarmogi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct point{ 5 | float x; 6 | float y; 7 | }; 8 | 9 | void read_point(struct point *p); 10 | float eukleidia_apostasi(struct point A, struct point B); 11 | 12 | 13 | main() 14 | { 15 | struct point A, B; 16 | 17 | printf("1o simeio: \n"); 18 | read_point(&A); 19 | printf("2o simeio: \n"); 20 | read_point(&B); 21 | 22 | printf("H eukleidia apostasi einai: %.3f",eukleidia_apostasi(A,B)); 23 | } 24 | 25 | void read_point(struct point *p) 26 | { 27 | printf("Dwse tin x sintetagmeni: "); 28 | scanf("%f", &p->x); 29 | 30 | printf("Dwse tin y sintetagmeni: "); 31 | scanf("%f", &p->y); 32 | } 33 | 34 | float eukleidia_apostasi(struct point A, struct point B) 35 | { 36 | return sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2)); 37 | } 38 | -------------------------------------------------------------------------------- /lesson13/efarmogi2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SIZE 80 4 | 5 | struct person{ 6 | char onoma[SIZE]; 7 | char diefthinsi[SIZE]; 8 | char arithmos[SIZE]; 9 | char nomos[SIZE]; 10 | }; 11 | 12 | typedef struct person RECORD; 13 | 14 | void read_record(RECORD *p); 15 | void print_record(RECORD x); 16 | 17 | main() 18 | { 19 | RECORD a,b; 20 | 21 | printf("1o atomo: \n"); 22 | read_record(&a); 23 | printf("2o atomo: \n"); 24 | read_record(&b); 25 | 26 | print_record(a); 27 | print_record(b); 28 | } 29 | 30 | void read_record(RECORD *p) 31 | { 32 | printf("Dwse to onoma: "); 33 | scanf("%s", p->onoma); 34 | 35 | printf("Dwse ti diefthinsi: "); 36 | scanf("%s", p->diefthinsi); 37 | 38 | printf("Dwse ton arithmo: "); 39 | scanf("%s", p->arithmos); 40 | 41 | printf("Dwse to nomo: "); 42 | scanf("%s", p->nomos); 43 | } 44 | 45 | void print_record(RECORD x) 46 | { 47 | printf("\n%s: %s %s %s",x.onoma, x.diefthinsi, x.arithmos, x.nomos); 48 | } 49 | -------------------------------------------------------------------------------- /lesson13/efarmogi3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SIZE 80 5 | 6 | struct person{ 7 | char *onoma; 8 | char *diefthinsi; 9 | char *arithmos; 10 | char *nomos; 11 | }; 12 | 13 | typedef struct person RECORD; 14 | 15 | void read_record(RECORD *p); 16 | void print_record(RECORD x); 17 | void init_record(RECORD *p); 18 | void free_record(RECORD x); 19 | 20 | main() 21 | { 22 | RECORD a,b; 23 | 24 | init_record(&a); 25 | init_record(&b); 26 | 27 | printf("1o atomo: \n"); 28 | read_record(&a); 29 | printf("2o atomo: \n"); 30 | read_record(&b); 31 | 32 | print_record(a); 33 | print_record(b); 34 | 35 | free_record(a); 36 | free_record(b); 37 | } 38 | 39 | void read_record(RECORD *p) 40 | { 41 | printf("Dwse to onoma: "); 42 | scanf("%s", p->onoma); 43 | 44 | printf("Dwse ti diefthinsi: "); 45 | scanf("%s", p->diefthinsi); 46 | 47 | printf("Dwse ton arithmo: "); 48 | scanf("%s", p->arithmos); 49 | 50 | printf("Dwse to nomo: "); 51 | scanf("%s", p->nomos); 52 | } 53 | 54 | void print_record(RECORD x) 55 | { 56 | printf("\n%s: %s %s %s",x.onoma, x.diefthinsi, x.arithmos, x.nomos); 57 | } 58 | 59 | void init_record(RECORD *p) 60 | { 61 | p->onoma = malloc(sizeof(char)*SIZE); 62 | if (!p->onoma) 63 | { 64 | printf("Adynamia desmeusis mnimis "); 65 | exit(0); 66 | } 67 | 68 | p->diefthinsi = malloc(sizeof(char)*SIZE); 69 | if (!p->diefthinsi) 70 | { 71 | printf("Adynamia desmeusis mnimis "); 72 | exit(0); 73 | } 74 | 75 | p->arithmos = malloc(sizeof(char)*SIZE); 76 | if (!p->arithmos) 77 | { 78 | printf("Adynamia desmeusis mnimis "); 79 | exit(0); 80 | } 81 | p->nomos = malloc(sizeof(char)*SIZE); 82 | if (!p->nomos) 83 | { 84 | printf("Adynamia desmeusis mnimis "); 85 | exit(0); 86 | } 87 | } 88 | 89 | void free_record(RECORD x) 90 | { 91 | free(x.onoma); 92 | free(x.diefthinsi); 93 | free(x.arithmos); 94 | free(x.nomos); 95 | } 96 | -------------------------------------------------------------------------------- /lesson13/efarmogi4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define N 3 5 | 6 | #define SIZE 80 7 | 8 | struct person{ 9 | char *onoma; 10 | char *diefthinsi; 11 | char *arithmos; 12 | char *nomos; 13 | }; 14 | 15 | typedef struct person RECORD; 16 | 17 | void read_record(RECORD *p); 18 | void print_record(RECORD x); 19 | void init_record(RECORD *p); 20 | void free_record(RECORD x); 21 | 22 | main() 23 | { 24 | RECORD pinakas[N]; 25 | int i; 26 | 27 | /* Arxikopoiisi twn stigmiotypwn */ 28 | for (i=0; ionoma); 53 | 54 | printf("Dwse ti diefthinsi: "); 55 | scanf("%s", p->diefthinsi); 56 | 57 | printf("Dwse ton arithmo: "); 58 | scanf("%s", p->arithmos); 59 | 60 | printf("Dwse to nomo: "); 61 | scanf("%s", p->nomos); 62 | } 63 | 64 | void print_record(RECORD x) 65 | { 66 | printf("\n%s: %s %s %s",x.onoma, x.diefthinsi, x.arithmos, x.nomos); 67 | } 68 | 69 | void init_record(RECORD *p) 70 | { 71 | p->onoma = malloc(sizeof(char)*SIZE); 72 | if (!p->onoma) 73 | { 74 | printf("Adynamia desmeusis mnimis "); 75 | exit(0); 76 | } 77 | 78 | p->diefthinsi = malloc(sizeof(char)*SIZE); 79 | if (!p->diefthinsi) 80 | { 81 | printf("Adynamia desmeusis mnimis "); 82 | exit(0); 83 | } 84 | 85 | p->arithmos = malloc(sizeof(char)*SIZE); 86 | if (!p->arithmos) 87 | { 88 | printf("Adynamia desmeusis mnimis "); 89 | exit(0); 90 | } 91 | p->nomos = malloc(sizeof(char)*SIZE); 92 | if (!p->nomos) 93 | { 94 | printf("Adynamia desmeusis mnimis "); 95 | exit(0); 96 | } 97 | } 98 | 99 | void free_record(RECORD x) 100 | { 101 | free(x.onoma); 102 | free(x.diefthinsi); 103 | free(x.arithmos); 104 | free(x.nomos); 105 | } 106 | -------------------------------------------------------------------------------- /lesson13/efarmogi5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SIZE 80 5 | 6 | struct person{ 7 | char *onoma; 8 | char *diefthinsi; 9 | char *arithmos; 10 | char *nomos; 11 | }; 12 | 13 | typedef struct person RECORD; 14 | 15 | void read_record(RECORD *p); 16 | void print_record(RECORD x); 17 | void init_record(RECORD *p); 18 | void free_record(RECORD x); 19 | 20 | main() 21 | { 22 | RECORD *pinakas; 23 | int i,N; 24 | 25 | printf("Dwse to plithos twn eggrafwn: "); 26 | scanf("%d", &N); 27 | 28 | pinakas=malloc(sizeof(RECORD)*N); 29 | if(!pinakas) 30 | { 31 | printf("Adynamia Desmeusis Mnimis"); 32 | exit(0); 33 | } 34 | 35 | /* Arxikopoiisi twn stigmiotypwn */ 36 | for (i=0; ionoma); 62 | 63 | printf("Dwse ti diefthinsi: "); 64 | scanf("%s", p->diefthinsi); 65 | 66 | printf("Dwse ton arithmo: "); 67 | scanf("%s", p->arithmos); 68 | 69 | printf("Dwse to nomo: "); 70 | scanf("%s", p->nomos); 71 | } 72 | 73 | void print_record(RECORD x) 74 | { 75 | printf("\n%s: %s %s %s",x.onoma, x.diefthinsi, x.arithmos, x.nomos); 76 | } 77 | 78 | void init_record(RECORD *p) 79 | { 80 | p->onoma = malloc(sizeof(char)*SIZE); 81 | if (!p->onoma) 82 | { 83 | printf("Adynamia desmeusis mnimis "); 84 | exit(0); 85 | } 86 | 87 | p->diefthinsi = malloc(sizeof(char)*SIZE); 88 | if (!p->diefthinsi) 89 | { 90 | printf("Adynamia desmeusis mnimis "); 91 | exit(0); 92 | } 93 | 94 | p->arithmos = malloc(sizeof(char)*SIZE); 95 | if (!p->arithmos) 96 | { 97 | printf("Adynamia desmeusis mnimis "); 98 | exit(0); 99 | } 100 | p->nomos = malloc(sizeof(char)*SIZE); 101 | if (!p->nomos) 102 | { 103 | printf("Adynamia desmeusis mnimis "); 104 | exit(0); 105 | } 106 | } 107 | 108 | void free_record(RECORD x) 109 | { 110 | free(x.onoma); 111 | free(x.diefthinsi); 112 | free(x.arithmos); 113 | free(x.nomos); 114 | } 115 | -------------------------------------------------------------------------------- /lesson13/efarmogi6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define SIZE 80 6 | 7 | struct person{ 8 | char *onoma; 9 | char *diefthinsi; 10 | char *arithmos; 11 | char *nomos; 12 | }; 13 | 14 | typedef struct person RECORD; 15 | 16 | void read_record(RECORD *p); 17 | void print_record(RECORD x); 18 | void init_record(RECORD *p); 19 | void free_record(RECORD x); 20 | void copy_record(RECORD *dest, RECORD src); 21 | 22 | main() 23 | { 24 | RECORD *pinakas, x; 25 | int i,N, choice; 26 | 27 | printf("Dwse to plithos twn eggrafwn: "); 28 | scanf("%d", &N); 29 | 30 | pinakas=malloc(sizeof(RECORD)*N); 31 | if(!pinakas) 32 | { 33 | printf("Adynamia Desmeusis Mnimis"); 34 | exit(0); 35 | } 36 | 37 | /* Arxikopoiisi twn stigmiotypwn */ 38 | for (i=0; ionoma); 75 | 76 | printf("Dwse ti diefthinsi: "); 77 | scanf("%s", p->diefthinsi); 78 | 79 | printf("Dwse ton arithmo: "); 80 | scanf("%s", p->arithmos); 81 | 82 | printf("Dwse to nomo: "); 83 | scanf("%s", p->nomos); 84 | } 85 | 86 | void print_record(RECORD x) 87 | { 88 | printf("\n%s: %s %s %s",x.onoma, x.diefthinsi, x.arithmos, x.nomos); 89 | } 90 | 91 | void init_record(RECORD *p) 92 | { 93 | p->onoma = malloc(sizeof(char)*SIZE); 94 | if (!p->onoma) 95 | { 96 | printf("Adynamia desmeusis mnimis "); 97 | exit(0); 98 | } 99 | 100 | p->diefthinsi = malloc(sizeof(char)*SIZE); 101 | if (!p->diefthinsi) 102 | { 103 | printf("Adynamia desmeusis mnimis "); 104 | exit(0); 105 | } 106 | 107 | p->arithmos = malloc(sizeof(char)*SIZE); 108 | if (!p->arithmos) 109 | { 110 | printf("Adynamia desmeusis mnimis "); 111 | exit(0); 112 | } 113 | p->nomos = malloc(sizeof(char)*SIZE); 114 | if (!p->nomos) 115 | { 116 | printf("Adynamia desmeusis mnimis "); 117 | exit(0); 118 | } 119 | } 120 | 121 | void free_record(RECORD x) 122 | { 123 | free(x.onoma); 124 | free(x.diefthinsi); 125 | free(x.arithmos); 126 | free(x.nomos); 127 | } 128 | 129 | void copy_record(RECORD *dest, RECORD src) 130 | { 131 | strcpy(dest->onoma,src.onoma); 132 | strcpy(dest->diefthinsi,src.diefthinsi); 133 | strcpy(dest->arithmos,src.arithmos); 134 | strcpy(dest->nomos,src.nomos); 135 | } 136 | -------------------------------------------------------------------------------- /lesson13/struct.c: -------------------------------------------------------------------------------- 1 | /* struct.c Deixnei tin vasiki leitourgia mias domis*/ 2 | #include 3 | 4 | struct date{ 5 | int day; 6 | int month; 7 | int year; 8 | }; 9 | 10 | struct person{ 11 | char name[80]; 12 | char surname[80]; 13 | struct date gennisi; 14 | }; 15 | 16 | main() 17 | { 18 | struct person p; 19 | 20 | printf("Dwse to onoma: "); 21 | scanf("%s", p.name); 22 | 23 | printf("Dwse to eponimo: "); 24 | scanf("%s", p.surname); 25 | 26 | printf("Dwse imera gennisis: "); 27 | scanf("%d",&p.gennisi.day); 28 | 29 | printf("Dwse mina gennisis: "); 30 | scanf("%d",&p.gennisi.month); 31 | 32 | printf("Dwse etos gennisis: "); 33 | scanf("%d",&p.gennisi.year); 34 | 35 | printf("\n%s %s (%d/%d/%d)", p.name, p.surname, 36 | p.gennisi.day,p.gennisi.month,p.gennisi.year); 37 | } 38 | -------------------------------------------------------------------------------- /lesson13/struct_array.c: -------------------------------------------------------------------------------- 1 | /* struct_array.c: Epeksergasia enos pinaka apo stigmiotupa domis */ 2 | 3 | #include 4 | #include 5 | 6 | #define STRING_SIZE 100 7 | 8 | struct epafi { 9 | char name[STRING_SIZE]; 10 | char phone[STRING_SIZE]; 11 | }; 12 | 13 | main() 14 | { 15 | struct epafi *pinakas; 16 | int i,N; 17 | 18 | /* 1. Eisagwgi tis diastasis toy pinaka */ 19 | printf("Dwse plithos epafwn: "); 20 | scanf("%d",&N); 21 | 22 | /* 2. Desmeusi Mnimis */ 23 | pinakas=malloc(sizeof(struct epafi)*N); 24 | if (!pinakas) 25 | { 26 | printf("Adynamia desmeusis mnimis"); 27 | exit(0); 28 | } 29 | 30 | /*3. Diavasma epafwn */ 31 | fflush(stdin); 32 | for (i=0; i 4 | 5 | union shared{ 6 | char c; 7 | int i; 8 | double d; 9 | }; 10 | 11 | main() 12 | { 13 | union shared s; 14 | 15 | s.c='a'; 16 | printf("\nXaraktiras: %c", s.c); 17 | printf("\nAkeraios : %d", s.i); 18 | printf("\nDouble : %f", s.d); 19 | 20 | s.d=10.55; 21 | printf("\nXaraktiras: %c", s.c); 22 | printf("\nAkeraios : %d", s.i); 23 | printf("\nDouble : %f", s.d); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /lesson14/c_language_lesson_14_emveleia(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson14/c_language_lesson_14_emveleia(4sl).pdf -------------------------------------------------------------------------------- /lesson14/c_language_lesson_14_emveleia.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson14/c_language_lesson_14_emveleia.pdf -------------------------------------------------------------------------------- /lesson14/efarmogi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fibonacci(int n); 4 | 5 | main() 6 | { 7 | int n; 8 | 9 | printf("Dwse ton arithmo: "); 10 | scanf("%d",&n); 11 | 12 | printf("O arithmos Fibonacci-%d einai %d", n, fibonacci(n)); 13 | } 14 | 15 | int fibonacci(int n) 16 | { 17 | static int count=0; 18 | 19 | count++; 20 | printf("\n%d", count); 21 | 22 | if (n==1 || n==2) 23 | return 1; 24 | else 25 | return fibonacci(n-1)+fibonacci(n-2); 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /lesson14/global.c: -------------------------------------------------------------------------------- 1 | /* global.c: Deixnei tin xrisi twn katholikwn metavlitwn */ 2 | #include 3 | 4 | int x; /* Katholiki metavliti */ 5 | void func(); 6 | 7 | main() 8 | { 9 | x=5; 10 | printf("\nMain: x=%d",x); 11 | func(); 12 | printf("\nMain: x=%d",x); 13 | } 14 | 15 | void func() 16 | { 17 | printf("\nFunc: x=%d",x); 18 | x=8; 19 | printf("\nFunc: x=%d",x); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /lesson14/lib_array.c: -------------------------------------------------------------------------------- 1 | /* lib_array.c: Kwdikas twn sinartisewn */ 2 | 3 | #include 4 | #include 5 | #include "lib_array.h" 6 | 7 | void init_array(int *pinakas, int n, int a, int b) 8 | { 9 | int i; 10 | 11 | srand(time(NULL)); 12 | 13 | for (i=0; i 3 | 4 | int x; /* Katholiki Metavliti */ 5 | void func(); 6 | 7 | main() 8 | { 9 | x=1; 10 | func(); 11 | 12 | } 13 | 14 | void func() 15 | { 16 | int x=5; /* Topiki Metavliti */ 17 | printf("\nLocal: x=%d",x); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lesson14/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "lib_array.h" 3 | 4 | #define N 50 5 | 6 | main() 7 | { 8 | int pin[N]; 9 | init_array(pin,N,1,100); 10 | 11 | print_array(pin,N); 12 | 13 | printf("\n\nTo athroisma einai: %d\n\n", sum_array(pin,N)); 14 | } 15 | -------------------------------------------------------------------------------- /lesson14/manip_array.dev: -------------------------------------------------------------------------------- 1 | [Project] 2 | FileName=manip_array.dev 3 | Name=Project2 4 | Type=1 5 | Ver=2 6 | ObjFiles= 7 | Includes= 8 | Libs= 9 | PrivateResource= 10 | ResourceIncludes= 11 | MakeIncludes= 12 | Compiler= 13 | CppCompiler= 14 | Linker= 15 | IsCpp=0 16 | Icon= 17 | ExeOutput= 18 | ObjectOutput= 19 | LogOutput= 20 | LogOutputEnabled=0 21 | OverrideOutput=0 22 | OverrideOutputName= 23 | HostApplication= 24 | UseCustomMakefile=0 25 | CustomMakefile= 26 | CommandLine= 27 | Folders= 28 | IncludeVersionInfo=0 29 | SupportXPThemes=0 30 | CompilerSet=0 31 | CompilerSettings= 32 | UnitCount=3 33 | 34 | [VersionInfo] 35 | Major=1 36 | Minor=0 37 | Release=0 38 | Build=0 39 | LanguageID=1033 40 | CharsetID=1252 41 | CompanyName= 42 | FileVersion= 43 | FileDescription=Developed using the Dev-C++ IDE 44 | InternalName= 45 | LegalCopyright= 46 | LegalTrademarks= 47 | OriginalFilename= 48 | ProductName= 49 | ProductVersion= 50 | AutoIncBuildNr=0 51 | SyncProduct=1 52 | 53 | [Unit2] 54 | FileName=lib_array.h 55 | CompileCpp=0 56 | Folder=Project2 57 | Compile=1 58 | Link=1 59 | Priority=1000 60 | OverrideBuildCmd=0 61 | BuildCmd= 62 | 63 | [Unit3] 64 | FileName=main.c 65 | CompileCpp=0 66 | Folder=Project2 67 | Compile=1 68 | Link=1 69 | Priority=1000 70 | OverrideBuildCmd=0 71 | BuildCmd= 72 | 73 | [Unit1] 74 | FileName=lib_array.c 75 | CompileCpp=0 76 | Folder=Project2 77 | Compile=1 78 | Link=1 79 | Priority=1000 80 | OverrideBuildCmd=0 81 | BuildCmd= 82 | 83 | -------------------------------------------------------------------------------- /lesson14/orismata.c: -------------------------------------------------------------------------------- 1 | /* local.c: Deixnei tin antimetwpisi sigkrousis onomatwn metavlitwn */ 2 | #include 3 | 4 | int x; /* Katholiki Metavliti */ 5 | void func(); 6 | 7 | main() 8 | { 9 | x=1; 10 | func(4); 11 | 12 | } 13 | 14 | void func(int x) 15 | { 16 | printf("\nLocal: x=%d",x); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /lesson14/record.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "record.h" 5 | 6 | 7 | void read_record(RECORD *p) 8 | { 9 | printf("Dwse to onoma: "); 10 | scanf("%s", p->onoma); 11 | 12 | printf("Dwse ti diefthinsi: "); 13 | scanf("%s", p->diefthinsi); 14 | 15 | printf("Dwse ton arithmo: "); 16 | scanf("%s", p->arithmos); 17 | 18 | printf("Dwse to nomo: "); 19 | scanf("%s", p->nomos); 20 | } 21 | 22 | void print_record(RECORD x) 23 | { 24 | printf("\n%s: %s %s %s",x.onoma, x.diefthinsi, x.arithmos, x.nomos); 25 | } 26 | 27 | void init_record(RECORD *p) 28 | { 29 | p->onoma = malloc(sizeof(char)*SIZE); 30 | if (!p->onoma) 31 | { 32 | printf("Adynamia desmeusis mnimis "); 33 | exit(0); 34 | } 35 | 36 | p->diefthinsi = malloc(sizeof(char)*SIZE); 37 | if (!p->diefthinsi) 38 | { 39 | printf("Adynamia desmeusis mnimis "); 40 | exit(0); 41 | } 42 | 43 | p->arithmos = malloc(sizeof(char)*SIZE); 44 | if (!p->arithmos) 45 | { 46 | printf("Adynamia desmeusis mnimis "); 47 | exit(0); 48 | } 49 | p->nomos = malloc(sizeof(char)*SIZE); 50 | if (!p->nomos) 51 | { 52 | printf("Adynamia desmeusis mnimis "); 53 | exit(0); 54 | } 55 | } 56 | 57 | void free_record(RECORD x) 58 | { 59 | free(x.onoma); 60 | free(x.diefthinsi); 61 | free(x.arithmos); 62 | free(x.nomos); 63 | } 64 | 65 | void copy_record(RECORD *dest, RECORD src) 66 | { 67 | strcpy(dest->onoma,src.onoma); 68 | strcpy(dest->diefthinsi,src.diefthinsi); 69 | strcpy(dest->arithmos,src.arithmos); 70 | strcpy(dest->nomos,src.nomos); 71 | } 72 | -------------------------------------------------------------------------------- /lesson14/record.dev: -------------------------------------------------------------------------------- 1 | [Project] 2 | FileName=record.dev 3 | Name=record 4 | Type=1 5 | Ver=2 6 | ObjFiles= 7 | Includes= 8 | Libs= 9 | PrivateResource= 10 | ResourceIncludes= 11 | MakeIncludes= 12 | Compiler= 13 | CppCompiler= 14 | Linker= 15 | IsCpp=0 16 | Icon= 17 | ExeOutput= 18 | ObjectOutput= 19 | LogOutput= 20 | LogOutputEnabled=0 21 | OverrideOutput=0 22 | OverrideOutputName= 23 | HostApplication= 24 | UseCustomMakefile=0 25 | CustomMakefile= 26 | CommandLine= 27 | Folders= 28 | IncludeVersionInfo=0 29 | SupportXPThemes=0 30 | CompilerSet=0 31 | CompilerSettings= 32 | UnitCount=3 33 | 34 | [VersionInfo] 35 | Major=1 36 | Minor=0 37 | Release=0 38 | Build=0 39 | LanguageID=1033 40 | CharsetID=1252 41 | CompanyName= 42 | FileVersion= 43 | FileDescription=Developed using the Dev-C++ IDE 44 | InternalName= 45 | LegalCopyright= 46 | LegalTrademarks= 47 | OriginalFilename= 48 | ProductName= 49 | ProductVersion= 50 | AutoIncBuildNr=0 51 | SyncProduct=1 52 | 53 | [Unit2] 54 | FileName=record.c 55 | CompileCpp=0 56 | Folder= 57 | Compile=1 58 | Link=1 59 | Priority=1000 60 | OverrideBuildCmd=0 61 | BuildCmd= 62 | 63 | [Unit3] 64 | FileName=record_main.c 65 | CompileCpp=0 66 | Folder= 67 | Compile=1 68 | Link=1 69 | Priority=1000 70 | OverrideBuildCmd=0 71 | BuildCmd= 72 | 73 | [Unit1] 74 | FileName=record.h 75 | CompileCpp=0 76 | Folder= 77 | Compile=1 78 | Link=1 79 | Priority=1000 80 | OverrideBuildCmd=0 81 | BuildCmd= 82 | 83 | -------------------------------------------------------------------------------- /lesson14/record.h: -------------------------------------------------------------------------------- 1 | 2 | #define SIZE 80 3 | 4 | struct person{ 5 | char *onoma; 6 | char *diefthinsi; 7 | char *arithmos; 8 | char *nomos; 9 | }; 10 | 11 | typedef struct person RECORD; 12 | 13 | void read_record(RECORD *p); 14 | void print_record(RECORD x); 15 | void init_record(RECORD *p); 16 | void free_record(RECORD x); 17 | void copy_record(RECORD *dest, RECORD src); 18 | 19 | -------------------------------------------------------------------------------- /lesson14/record_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "record.h" 4 | 5 | main() 6 | { 7 | RECORD *pinakas, x; 8 | int i,N, choice; 9 | 10 | printf("Dwse to plithos twn eggrafwn: "); 11 | scanf("%d", &N); 12 | 13 | pinakas=malloc(sizeof(RECORD)*N); 14 | if(!pinakas) 15 | { 16 | printf("Adynamia Desmeusis Mnimis"); 17 | exit(0); 18 | } 19 | 20 | /* Arxikopoiisi twn stigmiotypwn */ 21 | for (i=0; i 3 | 4 | void func(); 5 | 6 | main() 7 | { 8 | int i; 9 | 10 | for (i=0; i<10; i++) 11 | func(); 12 | } 13 | 14 | void func() 15 | { 16 | int y=0; 17 | static int x=0; 18 | 19 | x=x+1; 20 | y=y+1; 21 | printf("\nx=%d, y=%d", x,y); 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /lesson15/askisi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | main() 5 | { 6 | char c; 7 | 8 | c = getch(); 9 | while (c!='.') 10 | { 11 | if (c>='a' && c<='z') 12 | c-=32; 13 | printf("%c",c); 14 | 15 | c=getch(); 16 | } 17 | printf("%c",c); 18 | } 19 | -------------------------------------------------------------------------------- /lesson15/askisi2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define N 10 4 | 5 | main() 6 | { 7 | char string[N]; 8 | char check[2]; 9 | int i; 10 | 11 | printf("Dwse simvoloseira: "); 12 | 13 | fgets(string, N, stdin); 14 | 15 | for (i=0; i 4 | 5 | main() 6 | { 7 | int x,y,z; 8 | char c; 9 | 10 | printf("Dwse enan tripsifio arithmo:"); 11 | scanf("%1d%1d%1d", &x,&y,&z); 12 | 13 | fflush(stdin); 14 | 15 | printf("Epelekse M-Monades,D-Dekades,E-Ekatontades: "); 16 | scanf("%c",&c); 17 | 18 | switch(c) 19 | { 20 | case 'M': 21 | printf("Monades=%d",z); 22 | break; 23 | case 'D': 24 | printf("Dekades=%d",y); 25 | break; 26 | case 'E': 27 | printf("Ekatontades=%d",z); 28 | break; 29 | default: 30 | printf("Lathos eisodos!"); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /lesson15/fflush_wrong.c: -------------------------------------------------------------------------------- 1 | /* fflush_wrong.c: Epideiksi tis entolis ungetc */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int x,y,z; 8 | char c; 9 | 10 | printf("Dwse enan tripsifio arithmo:"); 11 | scanf("%1d%1d%1d", &x,&y,&z); 12 | 13 | printf("Epelekse M-Monades,D-Dekades,E-Ekatontades: "); 14 | scanf("%c",&c); 15 | switch(c) 16 | { 17 | case 'M': 18 | printf("Monades=%d",z); 19 | break; 20 | case 'D': 21 | printf("Dekades=%d",y); 22 | break; 23 | case 'E': 24 | printf("Ekatontades=%d",z); 25 | break; 26 | default: 27 | printf("Lathos eisodos!"); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /lesson15/fgets.c: -------------------------------------------------------------------------------- 1 | /* fgets.c: Epideiksi tis entolis fgets */ 2 | 3 | #include 4 | 5 | #define N 10 6 | 7 | main() 8 | { 9 | char buffer[N]; 10 | 11 | while(1) 12 | { 13 | fgets(buffer,N,stdin); 14 | printf("Eisodos: %s\n",buffer); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson15/getch.c: -------------------------------------------------------------------------------- 1 | /* getch.c: Epideiksi tis entolis getch */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | char c; 8 | 9 | c=getch(); 10 | while(c!='x') 11 | { 12 | printf("%c,",c); 13 | c=getch(); 14 | } 15 | printf("%c.",c); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson15/getchar.c: -------------------------------------------------------------------------------- 1 | /* getchar.c: Epideiksi tis entolis getchar */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | char c; 8 | 9 | c=getchar(); 10 | while(c!='x') 11 | { 12 | printf("%c,",c); 13 | c=getchar(); 14 | } 15 | printf("%c.",c); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson15/getche.c: -------------------------------------------------------------------------------- 1 | /* getch.c: Epideiksi tis entolis getch */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | char c; 8 | 9 | c=getche(); 10 | while(c!='x') 11 | { 12 | printf("%c,",c); 13 | c=getche(); 14 | } 15 | printf("%c.",c); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson15/scanf.c: -------------------------------------------------------------------------------- 1 | /* scanf.c: Epideiksi tis entolis scanf */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | char buffer[80]; 8 | 9 | printf("Eisagete simvoloseira: "); 10 | scanf("%[abcdef]",buffer); 11 | printf("Diavastike: %s\n",buffer); 12 | printf("Eisagete simvoloseira: "); 13 | scanf("%[^abcdef]",buffer); 14 | printf("Diavastike: %s",buffer); 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lesson15/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int i; 6 | char c; 7 | 8 | scanf("%d", &i); 9 | scanf("%c", &c); 10 | 11 | if (c=='\n') 12 | printf("Den diavazetai to Enter!"); 13 | } 14 | -------------------------------------------------------------------------------- /lesson15/ungetc.c: -------------------------------------------------------------------------------- 1 | /* ungetc.c: Epideiksi tis entolis ungetc */ 2 | #include 3 | 4 | main() 5 | { 6 | char c; 7 | c=getchar(); 8 | while(c!='\n') 9 | { 10 | printf("%c",c); 11 | c=getchar(); 12 | if (c=='m') 13 | { 14 | printf("%c",c); 15 | ungetc('!',stdin); 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lesson16/askisi3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SIZE 100 4 | 5 | main() 6 | { 7 | char string[SIZE]; 8 | int ret; 9 | 10 | printf("Dwse simvoloseira: "); 11 | 12 | while (1) 13 | { 14 | ret=scanf("%s", string); 15 | printf("\n%d: %s", ret, string); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lesson16/c_language_lesson_16_sinartiseis_output(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson16/c_language_lesson_16_sinartiseis_output(4sl).pdf -------------------------------------------------------------------------------- /lesson16/c_language_lesson_16_sinartiseis_output.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson16/c_language_lesson_16_sinartiseis_output.pdf -------------------------------------------------------------------------------- /lesson16/efarmogi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | char string[100]; 6 | 7 | printf("Dwse ti simvoloseira: "); 8 | gets(string); 9 | 10 | printf("H symvoloseira einai: "); 11 | puts(string); 12 | } 13 | -------------------------------------------------------------------------------- /lesson16/efarmogi2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | char string[100]; 6 | char c; 7 | int i; 8 | 9 | printf("Dwse ti simvoloseira: "); 10 | c=getchar(); 11 | i=0; 12 | while (c!='\n') 13 | { 14 | string[i]=c; 15 | 16 | c=getchar(); 17 | i++; 18 | } 19 | string[i]='\0'; 20 | 21 | printf("H symvoloseira einai: "); 22 | i=0; 23 | while (string[i]!='\0') 24 | { 25 | putchar(string[i]); 26 | 27 | i++; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /lesson16/fprintf.c: -------------------------------------------------------------------------------- 1 | /* fprintf.c: Epideiksi tis puts */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int i; 8 | 9 | for (i=0; i<100; i++) 10 | { 11 | fprintf(stdout,"\n%d*%d*%d=%d",i,i,i,i*i*i); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /lesson16/fputc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | int i; 6 | 7 | for (i=40; i<100; i++) 8 | fputc(i,stdout); 9 | } 10 | -------------------------------------------------------------------------------- /lesson16/putchar.c: -------------------------------------------------------------------------------- 1 | /* putchar.c: Epideiksi tis putchar */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int i; 8 | 9 | for (i=40; i<100; i++) 10 | putchar(i); 11 | } 12 | -------------------------------------------------------------------------------- /lesson16/puts.c: -------------------------------------------------------------------------------- 1 | /* puts.c: Epideiksi tis puts */ 2 | 3 | #include 4 | 5 | main() 6 | { 7 | int i; 8 | char *s="Hello World!"; 9 | 10 | puts(s); 11 | puts("-----------------"); 12 | 13 | for (i=0; i<100; i++) 14 | { 15 | puts(&s[i]); 16 | 17 | if (s[i]=='\0') 18 | break; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /lesson17/argc_argv.c: -------------------------------------------------------------------------------- 1 | /* argc_argv.c: programma epideiksis 2 | lipsis orismatwn apo ti grammi entolis */ 3 | 4 | #include 5 | 6 | main(int argc, char *argv[]) 7 | { 8 | 9 | printf("Plithos = %d",argc); 10 | 11 | printf("\nOrismata = %s kai %s",argv[1],argv[2]); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /lesson17/argc_argv_loop.c: -------------------------------------------------------------------------------- 1 | /* argc_argv_loop.c Epideikniei tin xrisi 2 | orismatwn grammis entolis */ 3 | 4 | #include 5 | 6 | main(int argc, char *argv[]) 7 | { 8 | int i; 9 | 10 | printf("argc=%d",argc); 11 | for (i=0; i 4 | 5 | main(int argc, char *argv[]) 6 | { 7 | int x,y; 8 | 9 | if(argc!=3) 10 | { 11 | printf("Prepei na eisagete 2 orismata!"); 12 | } 13 | else 14 | { 15 | x=atoi(argv[1]); 16 | y=atoi(argv[2]); 17 | 18 | printf("\nOrismata = %d kai %d",x,y); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lesson17/c_language_lesson_17_leitourgiko_sistima(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson17/c_language_lesson_17_leitourgiko_sistima(4sl).pdf -------------------------------------------------------------------------------- /lesson17/c_language_lesson_17_leitourgiko_sistima.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson17/c_language_lesson_17_leitourgiko_sistima.pdf -------------------------------------------------------------------------------- /lesson17/efarmogi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void print_array(int *pinakas, int n); 5 | void insertion_sort(int *pinakas, int n); 6 | void swap(int *a, int *b); 7 | 8 | main(int argc, char *argv[]) 9 | { 10 | int *array; 11 | int i,N; 12 | 13 | N=argc-1; 14 | 15 | array=malloc(sizeof(int)*N); 16 | if (!array) 17 | { 18 | printf("Adynamia desmeusis mnimis!"); 19 | exit(0); 20 | } 21 | 22 | for (i=0; i=1; j--) 63 | { 64 | if (pinakas[j] 2 | #include 3 | #include 4 | 5 | int lexarithmos(char *s); 6 | void baba(int sum); 7 | 8 | main(int argc, char *argv[]) 9 | { 10 | int lexo,lexp,age,height,sum; 11 | 12 | lexo=lexarithmos(argv[1]); 13 | lexp=lexarithmos(argv[2]); 14 | 15 | age=10*atoi(argv[3]); 16 | 17 | height=(int)100*atof(argv[4]); 18 | 19 | sum=lexo+lexp+age+height; 20 | 21 | if (sum<=1000) 22 | baba(sum); 23 | else 24 | { 25 | baba(sum); 26 | srand(time(NULL)); 27 | baba(rand()%1000+1); 28 | } 29 | 30 | } 31 | 32 | nt lexarithmos(char *s) 33 | 34 | int sum,i; 35 | 36 | i=0; 37 | sum=0; 38 | while (s[i]!='\0') 39 | { 40 | sum+=s[i]-'a'+1; 41 | 42 | i++; 43 | } 44 | 45 | return sum; 46 | } 47 | 48 | void baba(int sum) 49 | { 50 | if (sum>=0 && sum<=300) 51 | printf("H baba leei: Seismos kai katapontismos!"); 52 | else if (sum>=301 && sum<=600) 53 | printf("H baba leei: Limos kai Polemos!"); 54 | else if (sum>=601 && sum<=1000) 55 | printf("H baba leei: Arrwstia kai Kasida!"); 56 | else if (sum>1000) 57 | printf("Dwse alla 100 euro!!"); 58 | } 59 | -------------------------------------------------------------------------------- /lesson17/file.txt: -------------------------------------------------------------------------------- 1 | 923 2 | 2 3 | 84 4 | 360 5 | 160 6 | 58 7 | 140 8 | 22 9 | 707 10 | 426 11 | 473 12 | 982 13 | 420 14 | 929 15 | 536 16 | 665 17 | 898 18 | 73 19 | 583 20 | 918 21 | -------------------------------------------------------------------------------- /lesson17/redirect_input.c: -------------------------------------------------------------------------------- 1 | /* redirect_input.c: tha to xrisimopoiisoume 2 | gia anakateuthinsi eisodou */ 3 | 4 | #include 5 | #define N 20 6 | 7 | main() 8 | { 9 | int i; 10 | int array[N]; 11 | 12 | for (i=0; i 5 | #include 6 | #include 7 | 8 | main() 9 | { 10 | int i; 11 | 12 | srand(time(NULL)); 13 | for (i=0; i<20; i++) 14 | printf("%d\n",rand()%1000); 15 | } 16 | -------------------------------------------------------------------------------- /lesson18/C.18(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson18/C.18(4sl).pdf -------------------------------------------------------------------------------- /lesson18/C.18.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson18/C.18.pdf -------------------------------------------------------------------------------- /lesson18/ask1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define N 10 6 | #define SIZE 100 7 | 8 | void swap(char **a, char **b); 9 | 10 | main() 11 | { 12 | char *pin[N]; 13 | int i,j; 14 | 15 | /* Arxikopoiisi */ 16 | for (i=0; i=i+1; j--) 32 | { 33 | if (strcmp(pin[j],pin[j-1])<0) 34 | swap(&pin[j], &pin[j-1]); 35 | } 36 | } 37 | 38 | /* Ektypwsi */ 39 | for (i=0; i 2 | #include 3 | #include 4 | 5 | #define N 10 6 | #define SIZE 100 7 | 8 | void swap(char **a, char **b); 9 | 10 | main() 11 | { 12 | char s[SIZE]; 13 | char *pin[N]; 14 | char *ptr; 15 | int i,j,n; 16 | 17 | /* Arxikopoiisi */ 18 | 19 | printf("Dwse frasi: "); 20 | gets(s); 21 | 22 | ptr=s; 23 | ptr=strtok(ptr," "); 24 | i=0; 25 | while(ptr!=NULL) 26 | { 27 | pin[i]=(char *)malloc(SIZE*sizeof(char)); 28 | if (pin[i]==NULL) 29 | { 30 | printf("Error allocating memory!"); 31 | exit(0); 32 | } 33 | strcpy(pin[i],ptr); 34 | 35 | ptr=strtok(NULL, " "); 36 | i++; 37 | } 38 | n=i; 39 | 40 | /* Taksinomisi */ 41 | for (i=0; i=i+1; j--) 44 | { 45 | if (strcmp(pin[j],pin[j-1])<0) 46 | swap(&pin[j], &pin[j-1]); 47 | } 48 | } 49 | 50 | /* Ektypwsi */ 51 | for (i=0; i 4 | #include 5 | 6 | #define N 80 7 | 8 | main() 9 | { 10 | char str1[N], str2[N]; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira 1: "); 14 | gets(str1); 15 | printf("Dwse ti simvoloseira 2: "); 16 | gets(str2); 17 | 18 | /* antigrafi me tin strcat */ 19 | strcat(str1,str2); 20 | printf("\nstr1=%s",str1); 21 | strcat(str1,str2); 22 | printf("\nstr1=%s",str1); 23 | } 24 | -------------------------------------------------------------------------------- /lesson18/strchr.c: -------------------------------------------------------------------------------- 1 | /* strchr.c: Anadeiknyei ti xrisi tis strchr */ 2 | #include 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | int i; 10 | char str[N], ch; 11 | char *ptr; 12 | 13 | /* eisodos */ 14 | printf("Dwse ti simvoloseira: "); 15 | gets(str); 16 | printf("Dwse to xaraktira: "); 17 | ch=getchar(); 18 | /* anazitisi me tin strchr */ 19 | ptr=strchr(str,ch); 20 | while(ptr!=NULL) 21 | { 22 | puts(ptr); 23 | ptr=strchr(ptr+1,ch); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lesson18/strcmp.c: -------------------------------------------------------------------------------- 1 | /* strcmp.c: Anadeiknyei ti xrisi tis strcmp */ 2 | #include 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | int res; 10 | char str1[N], str2[N]; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira 1: "); 14 | gets(str1); 15 | printf("Dwse ti simvoloseira 2: "); 16 | gets(str2); 17 | 18 | /* sygrisi me tin strcmp */ 19 | res=strcmp(str1,str2); 20 | if (res<0) 21 | printf("str1str2 (res=%d)",res); 26 | } 27 | -------------------------------------------------------------------------------- /lesson18/strcpy.c: -------------------------------------------------------------------------------- 1 | /* strcpy.c: Epideikniei ti xrisi tis strcpy */ 2 | 3 | #include 4 | #include 5 | 6 | #define N 80 7 | 8 | main() 9 | { 10 | char str1[N], str2[N]; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira: "); 14 | gets(str1); 15 | 16 | /* antigrafi me tin strcpy */ 17 | strcpy(str2,str1); 18 | 19 | /* eksodos */ 20 | printf("str1=%s, str2=%s",str1,str2); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /lesson18/strcspn.c: -------------------------------------------------------------------------------- 1 | /* strcspn.c: Anadeiknyei ti xrisi tis strcspn */ 2 | #include 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | char str[N], ch; 10 | int pos; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira: "); 14 | gets(str); 15 | 16 | /* anazitisi me tin strcspn */ 17 | pos=strcspn(str,"abc"); 18 | if (pos!=strlen(str)) 19 | printf("Apo ti thesi %d: %s",pos, &str[pos]); 20 | else 21 | printf("Den vrethikan oi xaraktires abc stin %s", str); 22 | } 23 | -------------------------------------------------------------------------------- /lesson18/strdup.c: -------------------------------------------------------------------------------- 1 | /* strdup.c: Anadeiknyei ti xrisi tis strdup */ 2 | #include 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | char str[N]; 10 | char *str2; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira: "); 14 | gets(str); 15 | /* antigrafi me tin strdup */ 16 | str2=strdup(str); 17 | /* eksodos */ 18 | if (!str2) 19 | { 20 | printf("Adynamia desmeusis mnimis!"); 21 | } 22 | else{ 23 | printf("Antigrafike: %s me mikos: %d",str2,strlen(str2)); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /lesson18/strlen.c: -------------------------------------------------------------------------------- 1 | /* strlen.c: Epideikniei ti xrisi tis strlen */ 2 | 3 | #include 4 | #include 5 | 6 | #define N 80 7 | 8 | main() 9 | { 10 | char str[N]; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira: "); 14 | gets(str); 15 | 16 | /* eksodos */ 17 | printf("Mikos=%d",strlen(str)); 18 | } 19 | -------------------------------------------------------------------------------- /lesson18/strncat.c: -------------------------------------------------------------------------------- 1 | /* strncat.c: Epideikniei ti xrisi tis strncat */ 2 | 3 | #include 4 | #include 5 | 6 | #define N 80 7 | 8 | main() 9 | { 10 | int i; 11 | char str1[N], str2[N]; 12 | 13 | /* eisodos */ 14 | printf("Dwse ti simvoloseira 1: "); 15 | gets(str1); 16 | printf("Dwse ti simvoloseira 2: "); 17 | gets(str2); 18 | 19 | /* antigrafi me tin strcat */ 20 | for (i=1; i<=5; i++) 21 | { 22 | strncat(str1,str2,i); 23 | printf("\nstr1=%s",str1); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lesson18/strncmp.c: -------------------------------------------------------------------------------- 1 | /* strncmp.c: Anadeiknyei ti xrisi tis strncmp */ 2 | #include 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | int res,l=4; 10 | char str1[N], str2[N]; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira 1: "); 14 | gets(str1); 15 | printf("Dwse ti simvoloseira 2: "); 16 | gets(str2); 17 | /* sygkrisi me tin strncmp */ 18 | res=strncmp(str1,str2,l); 19 | /* eksodos */ 20 | if (res<0) 21 | printf("str1str2 (res=%d)",res); 26 | } 27 | -------------------------------------------------------------------------------- /lesson18/strncpy.c: -------------------------------------------------------------------------------- 1 | /* strncpy.c: Epideikniei ti xrisi tis strncpy */ 2 | 3 | #include 4 | #include 5 | 6 | #define N 80 7 | 8 | main() 9 | { 10 | char str1[N], str2[N]; 11 | int l=5; 12 | 13 | /* eisodos */ 14 | printf("Dwse ti simvoloseira: "); 15 | gets(str1); 16 | 17 | /* antigrafi me tin strncpy */ 18 | strncpy(str2,str1,l); 19 | 20 | /* eksodos */ 21 | printf("str1=%s, str2=%s",str1,str2); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /lesson18/strrchr.c: -------------------------------------------------------------------------------- 1 | /* strrchr.c: Anadeiknyei ti xrisi tis strrchr */ 2 | #include 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | char str[N], ch; 10 | char *ptr; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira: "); 14 | gets(str); 15 | printf("Dwse to xaraktira: "); 16 | ch=getchar(); 17 | /* anazitisi me tin strrchr */ 18 | ptr=strrchr(str,ch); 19 | 20 | puts(ptr); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /lesson18/strspn.c: -------------------------------------------------------------------------------- 1 | /* strspn.c: Anadeiknyei ti xrisi tis strcspn */ 2 | #include 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | char str1[N], str2[N]; 10 | char *ptr; 11 | int i,length; 12 | 13 | /* eisodos */ 14 | printf("Dwse ti 1i simvoloseira: "); 15 | gets(str1); 16 | printf("Dwse ti 2i simvoloseira: "); 17 | gets(str2); 18 | 19 | /* anazitisi me tin strspn */ 20 | length=strspn(str1,str2); 21 | if (length>0) 22 | { 23 | printf("Oi prwtoi %d xaraktires tis str1 periexontai stin stin str2:",length); 24 | for (i=0; i 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | char str1[N], str2[N]; 10 | char *ptr; 11 | 12 | /* eisodos */ 13 | printf("Dwse to keimeno sto opoio anazitoume: "); 14 | gets(str1); 15 | printf("Dwse ti anazitoume: "); 16 | gets(str2); 17 | 18 | /* anazitisi me tin strstr */ 19 | ptr=strstr(str1,str2); 20 | while(ptr!=NULL) 21 | { 22 | printf("Stin thesi %d: %s\n",ptr-str1,ptr); 23 | ptr=strstr(ptr+1,str2); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lesson18/strtok.c: -------------------------------------------------------------------------------- 1 | /* strtok.c: Anadeiknyei ti xrisi tis strtok */ 2 | #include 3 | #include 4 | 5 | #define N 80 6 | 7 | main() 8 | { 9 | int i,res; 10 | char str[N], *p; 11 | 12 | /* eisodos */ 13 | printf("Dwse ti simvoloseira: "); 14 | gets(str); 15 | /* xwrismos me tin strtok */ 16 | p=strtok(str," ,."); 17 | /* eksodos */ 18 | while(p!=NULL) 19 | { 20 | printf("%s\n",p); 21 | p=strtok(NULL," ,."); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lesson19/C.19(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson19/C.19(4sl).pdf -------------------------------------------------------------------------------- /lesson19/C.19.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson19/C.19.pdf -------------------------------------------------------------------------------- /lesson19/askisi1.c: -------------------------------------------------------------------------------- 1 | /* c19.askisi1.c */ 2 | 3 | #include 4 | #include 5 | 6 | double f(double x); 7 | 8 | main() 9 | { 10 | double d; 11 | 12 | printf("Dwse double: "); 13 | scanf("%lf", &d); 14 | 15 | printf("Apotelesma: %lf", f(f(d))); 16 | } 17 | 18 | double f(double x) 19 | { 20 | return 1/(1+exp(-x)); 21 | } -------------------------------------------------------------------------------- /lesson19/askisi2.c: -------------------------------------------------------------------------------- 1 | /* c19.askisi2.c */ 2 | #include 3 | #include 4 | 5 | long fibonacci(int n); 6 | 7 | main() 8 | { 9 | int i; 10 | clock_t c1, c2; 11 | 12 | for (i=1; i<=50; i++) 13 | { 14 | c1=clock(); 15 | printf("fib(%d)=%ld",i,fibonacci(i)); 16 | c2=clock(); 17 | 18 | printf("\t Time=%lf\n",(double)(c2-c1)/CLOCKS_PER_SEC); 19 | } 20 | 21 | } 22 | 23 | long fibonacci(int n) 24 | { 25 | if (n==1 || n==2) 26 | return 1; 27 | else 28 | return fibonacci(n-1)+fibonacci(n-2); 29 | } -------------------------------------------------------------------------------- /lesson19/clock.c: -------------------------------------------------------------------------------- 1 | /* clock.c: Ektipwsi toy xronoy apo tin arxi toy programmatos */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | clock_t t; 8 | t = clock(); 9 | printf("Kikloi: %ld\n", t); 10 | 11 | printf("Kikloi ana deyterolepto: %ld\n", CLOCKS_PER_SEC); 12 | 13 | printf("Xronos apo tin enarksi: %f", (float)t/CLOCKS_PER_SEC); 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /lesson19/math.exp.c: -------------------------------------------------------------------------------- 1 | /* math.exp.c: Anadeiknyei tis sinartiseis ipswsis se dinami */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | double x,y; 8 | 9 | printf("pow"); 10 | printf("\nDwse vasi arithmou: "); 11 | scanf("%lf",&x); 12 | printf("Dwse ektheti arithmou: "); 13 | scanf("%lf",&y); 14 | printf("%lf%lf=%lf",x,y,pow(x,y)); 15 | } 16 | -------------------------------------------------------------------------------- /lesson19/math.floor-ceil.c: -------------------------------------------------------------------------------- 1 | /* math.sqrt.c: Anadeikniei ti xrisi rizwn sti C */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | double x; 8 | 9 | x=1.2; 10 | printf("\n x=%.2f: floor=%.2f, ceil=%.2f",x,floor(x),ceil(x)); 11 | x=1.5; 12 | printf("\n x=%.2f: floor=%.2f, ceil=%.2f",x,floor(x),ceil(x)); 13 | x=2.0; 14 | printf("\n x=%.2f: floor=%.2f, ceil=%.2f",x,floor(x),ceil(x)); 15 | } 16 | -------------------------------------------------------------------------------- /lesson19/math.frexp.c: -------------------------------------------------------------------------------- 1 | /* math.frexp.c: Anadeikniei tin frexp */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | double x,r; 8 | int y; 9 | 10 | for (x=0; x<15; x+=0.5) 11 | { 12 | r=frexp(x,&y); 13 | printf("\n %.2f = %.2f * 2^%d",x,r,y); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lesson19/math.modf.c: -------------------------------------------------------------------------------- 1 | /* math.modf.c: Anadeikniei ti xrisi tis modf */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | double x; 8 | double r,y; 9 | 10 | for (x=0.0; x<5.0; x+=0.6) 11 | { 12 | r=modf(x,&y); 13 | printf("\n%.2f = %.2f + %.2f",x,y,r); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /lesson19/math.sqrt.c: -------------------------------------------------------------------------------- 1 | /* math.sqrt.c: Anadeikniei ti xrisi rizwn sti C */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | double x=2.0; 8 | double y,r; 9 | 10 | r=sqrt(x); 11 | printf("sqrt(%.2f)=%.2f",x,r); 12 | 13 | for (y=1; y<10; y+=1.0) 14 | { 15 | r=pow(x,1/y); 16 | printf("\n %.2f^(1/%.2f) = %.2f",x,y,r); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lesson19/math.trig.c: -------------------------------------------------------------------------------- 1 | /* math.trig.c: Anadeiknyei tis trigonometrikes 2 | sinartiseis */ 3 | #include 4 | #include 5 | 6 | #define PI 3.1415926 7 | 8 | main() 9 | { 10 | int i; 11 | double v; 12 | 13 | for (i=0; i<4; i++) 14 | { 15 | v=i*(PI/2); 16 | printf("\nHmitono tou %d*PI/2=%.2f",i,sin(v)); 17 | printf("\nSinimitono tou %d*PI/2=%.2f",i,cos(v)); 18 | printf("\nEfaptomeni tou %d*PI/2=%.2f",i,tan(v)); 19 | printf("\n====================="); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lesson19/time.c: -------------------------------------------------------------------------------- 1 | /* time.c: Deuterolepta apo tin 1.1.1970 */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | time_t t; 8 | 9 | t = time(0); 10 | 11 | printf("Deyterolepta= %ld", t); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lesson19/time.convert.c: -------------------------------------------------------------------------------- 1 | /* time.convert.c: MEtatropes stis anaparastaseis */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | time_t t; 8 | struct tm *now; 9 | t = time(0); 10 | now = localtime(&t); 11 | printf("%d:%d:%d",now->tm_hour, now->tm_min, now->tm_sec); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lesson19/time.print.c: -------------------------------------------------------------------------------- 1 | /* time.print.c: Ektipwsi tou xronou */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | time_t t; 8 | t = time(0); 9 | printf("%s", ctime(&t)); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /lesson19/time.timer_program.c: -------------------------------------------------------------------------------- 1 | /* time.timer_program.c: Ypologismos Xronoy Ektelesis */ 2 | #include 3 | #include 4 | #define N 1000000000 5 | main() 6 | { 7 | clock_t c1,c2; 8 | long i; 9 | 10 | c1 = clock(); 11 | 12 | for (i=1; i<=N; i++); 13 | 14 | c2 = clock(); 15 | 16 | printf("time: Arxi=%ld, Telos=%ld, Xronos=%.3f", c1,c2, 17 | (float)(c2-c1)/CLOCKS_PER_SEC); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lesson20/askisi1.1.c: -------------------------------------------------------------------------------- 1 | /* askisi1.1.c */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | 8 | FILE *fp; 9 | 10 | fp=fopen("temp.txt","w"); 11 | if (!fp) exit(0); 12 | fprintf(fp, "0123456789"); 13 | fclose(fp); 14 | 15 | fp=fopen("temp.txt","a+"); 16 | printf("POS=%ld", ftell(fp)); 17 | 18 | fprintf(fp, "XXXX"); 19 | 20 | rewind(fp); 21 | 22 | while(!feof(fp)) 23 | printf("%c",fgetc(fp)); 24 | 25 | fclose(fp); 26 | } 27 | -------------------------------------------------------------------------------- /lesson20/askisi1.2.c: -------------------------------------------------------------------------------- 1 | /* askisi1.2.c */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | 8 | FILE *fp; 9 | 10 | fp=fopen("temp.txt","w"); 11 | if (!fp) exit(0); 12 | fprintf(fp, "0123456789"); 13 | fclose(fp); 14 | 15 | fp=fopen("temp.txt","r+"); 16 | printf("POS=%ld\n", ftell(fp)); 17 | 18 | while(!feof(fp)) 19 | printf("%c",fgetc(fp)); 20 | 21 | printf("\nPOS=%ld\n", ftell(fp)); 22 | 23 | rewind(fp); 24 | 25 | fprintf(fp, "XXXX"); 26 | 27 | rewind(fp); 28 | while(!feof(fp)) 29 | printf("%c",fgetc(fp)); 30 | 31 | fclose(fp); 32 | } 33 | -------------------------------------------------------------------------------- /lesson20/askisi1.3.c: -------------------------------------------------------------------------------- 1 | /* askisi1.3.c */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | 8 | FILE *fp; 9 | 10 | fp=fopen("temp.txt","w"); 11 | if (!fp) exit(0); 12 | fprintf(fp, "0123456789"); 13 | fclose(fp); 14 | 15 | fp=fopen("temp.txt","w+"); 16 | printf("POS=%ld\n", ftell(fp)); 17 | 18 | fprintf(fp,"0123"); 19 | 20 | rewind(fp); 21 | 22 | while(!feof(fp)) 23 | printf("%c", fgetc(fp)); 24 | 25 | fclose(fp); 26 | } 27 | -------------------------------------------------------------------------------- /lesson20/askisi2.c: -------------------------------------------------------------------------------- 1 | /* askisi2.c */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | FILE *fFrom; 8 | FILE *fTo; 9 | char filename[80]; 10 | char new_filename[80]; 11 | char c; 12 | 13 | printf("Dwse to arxeio pou thes na antigrapseis: "); 14 | scanf("%s", filename); 15 | 16 | fFrom = fopen(filename, "r"); 17 | if (!fFrom) 18 | { 19 | printf("To arxeio pigis den uparxei!"); 20 | exit(0); 21 | } 22 | 23 | printf("Dwse to neo arxeio: "); 24 | scanf("%s", new_filename); 25 | 26 | fTo = fopen(new_filename, "r"); 27 | if (fTo) 28 | { 29 | printf("To arxeio proorismou uparxei!"); 30 | exit(0); 31 | } 32 | fclose(fTo); 33 | 34 | fTo = fopen(new_filename, "w"); 35 | if (!fTo) 36 | { 37 | printf("Error opening file!"); 38 | exit(0); 39 | } 40 | 41 | while(1) 42 | { 43 | c=fgetc(fFrom); 44 | 45 | if (feof(fFrom)) 46 | break; 47 | 48 | fputc(c,fTo); 49 | } 50 | 51 | fclose(fFrom); 52 | fclose(fTo); 53 | } 54 | -------------------------------------------------------------------------------- /lesson20/askisi3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define TRUE 1 5 | #define FALSE 0 6 | 7 | #define SIZE 80 8 | 9 | struct record 10 | { 11 | char name[SIZE]; 12 | char surname[SIZE]; 13 | int age; 14 | int grade; 15 | }; 16 | 17 | 18 | int open(char *filename, FILE **fp, int *num); 19 | int close(FILE **fp); 20 | int add(FILE *fp); 21 | int read(FILE *fp, int num, int rec, struct record *eggrafi); 22 | int print(struct record temp); 23 | void print_all(FILE *fp, int num); 24 | int modify(FILE *fp, int num, int rec); 25 | 26 | main() 27 | { 28 | FILE *fp; 29 | int N; 30 | int choice, check, rec; 31 | char filename[]="data.dat"; 32 | struct record temp; 33 | 34 | while(1) 35 | { 36 | printf("\n\nMENU"); 37 | printf("\n============"); 38 | printf("\n1-Anoigma"); 39 | printf("\n2-Kleisimo"); 40 | printf("\n3-Prosthiki Eggrafis"); 41 | printf("\n4-Diavasma Eggrafis"); 42 | printf("\n5-Ektypwsi olwn twn eggrafwn"); 43 | printf("\n6-Tropopoiisi Eggrafis"); 44 | printf("\n7-Eksodos"); 45 | printf("\n============"); 46 | printf("\nEpilogi? "); 47 | scanf("%d", &choice); 48 | 49 | switch(choice) 50 | { 51 | case 1: 52 | check=open(filename, &fp, &N); 53 | if (check==TRUE) 54 | printf("To arxeio anoikse!"); 55 | else 56 | { 57 | printf("Error!"); 58 | exit(0); 59 | } 60 | break; 61 | case 2: 62 | check=close(&fp); 63 | if (check==TRUE) 64 | printf("To arxeio ekleise!"); 65 | else 66 | { 67 | printf("Error!"); 68 | exit(0); 69 | } 70 | break; 71 | case 3: 72 | check=add(fp); 73 | if (check==TRUE) 74 | { 75 | printf("H eggrafi prostethike!"); 76 | N++; 77 | } 78 | else 79 | { 80 | printf("Error!"); 81 | exit(0); 82 | } 83 | break; 84 | case 4: 85 | printf("Poia eggrafi thes? "); 86 | scanf("%d", &rec); 87 | check=read(fp, N, rec, &temp); 88 | if (check==FALSE) 89 | { 90 | printf("Error at index!"); 91 | continue; 92 | } 93 | printf("H eggrafi %d einai:", rec); 94 | print(temp); 95 | break; 96 | case 5: 97 | print_all(fp, N); 98 | break; 99 | case 6: 100 | printf("Poia eggrafi thes? "); 101 | scanf("%d", &rec); 102 | check=modify(fp, N, rec); 103 | if (check==FALSE) 104 | { 105 | printf("Error at index!"); 106 | continue; 107 | } 108 | break; 109 | case 7: 110 | printf("Bye bye!"); 111 | exit(0); 112 | default: 113 | printf("Lathos epilogi!"); 114 | } 115 | } 116 | } 117 | 118 | int open(char *filename, FILE **fp, int *num) 119 | { 120 | struct record temp; 121 | 122 | (*fp)=fopen(filename, "rb"); 123 | if ((*fp)==NULL) // to arxeio den yparxei 124 | { 125 | (*fp)=fopen(filename, "wb+"); 126 | if ((*fp)==NULL) 127 | { 128 | printf("Error Opening file!"); 129 | return FALSE; 130 | } 131 | *num=0; 132 | return TRUE; 133 | } 134 | else // To arxeio iparxei 135 | { 136 | fclose(*fp); 137 | (*fp)=fopen(filename, "rb+"); 138 | if ((*fp)==NULL) 139 | { 140 | printf("Error Opening file!"); 141 | return FALSE; 142 | } 143 | 144 | (*num)=0; 145 | while(fread(&temp,sizeof(struct record),1,(*fp))==1) 146 | (*num)++; 147 | 148 | return TRUE; 149 | } 150 | } 151 | 152 | int close(FILE **fp) 153 | { 154 | if (fclose(*fp)==0) 155 | return TRUE; 156 | else 157 | return FALSE; 158 | } 159 | 160 | int add(FILE *fp) 161 | { 162 | struct record temp; 163 | 164 | printf("Dwse onoma: "); 165 | scanf("%s", temp.name); 166 | printf("Dwse epwnimo: "); 167 | scanf("%s", temp.surname); 168 | printf("Dwse ilikia: "); 169 | scanf("%d", &temp.age); 170 | printf("Dwse vathmo: "); 171 | scanf("%d", &temp.grade); 172 | 173 | fseek(fp,0,SEEK_END); 174 | if (fwrite(&temp, sizeof(struct record), 1, fp)==1) 175 | return TRUE; 176 | else 177 | return FALSE; 178 | } 179 | 180 | int read(FILE *fp, int num, int rec, struct record *eggrafi) 181 | { 182 | if (rec>=0 && rec<=num-1) 183 | { 184 | fseek(fp,rec*sizeof(struct record),SEEK_SET); 185 | if (fread(eggrafi,sizeof(struct record),1,fp)==1) 186 | return TRUE; 187 | else 188 | return FALSE; 189 | } 190 | else 191 | return FALSE; 192 | } 193 | 194 | int print(struct record temp) 195 | { 196 | printf("\nOnoma : %s", temp.name); 197 | printf("\nEpwnimo: %s", temp.surname); 198 | printf("\nIlikia : %d", temp.age); 199 | printf("\nVathmos: %d\n\n", temp.grade); 200 | } 201 | 202 | void print_all(FILE *fp, int num) 203 | { 204 | int i; 205 | struct record temp; 206 | 207 | for (i=0; i=0 && rec<=num-1) 220 | { 221 | fseek(fp, rec*sizeof(struct record), SEEK_SET); 222 | fread(&temp, sizeof(struct record), 1, fp); 223 | 224 | printf("H arxiki eggrafi einai:\n"); 225 | print(temp); 226 | 227 | printf("Dwse onoma: "); 228 | scanf("%s", temp.name); 229 | printf("Dwse epwnimo: "); 230 | scanf("%s", temp.surname); 231 | printf("Dwse ilikia: "); 232 | scanf("%d", &temp.age); 233 | printf("Dwse vathmo: "); 234 | scanf("%d", &temp.grade); 235 | 236 | printf("H nea eggrafi einai:\n"); 237 | print(temp); 238 | 239 | fseek(fp, rec*sizeof(struct record), SEEK_SET); 240 | fwrite(&temp, sizeof(struct record), 1, fp); 241 | 242 | return TRUE; 243 | } 244 | else 245 | return FALSE; 246 | } 247 | -------------------------------------------------------------------------------- /lesson20/binarydata.dat: -------------------------------------------------------------------------------- 1 | )C"EN:>@-Q=[_*$ -------------------------------------------------------------------------------- /lesson20/c20(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson20/c20(4sl).pdf -------------------------------------------------------------------------------- /lesson20/c20.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson20/c20.pdf -------------------------------------------------------------------------------- /lesson20/data.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson20/data.dat -------------------------------------------------------------------------------- /lesson20/feof.c: -------------------------------------------------------------------------------- 1 | /* feof.c */ 2 | #include 3 | #include 4 | 5 | main() { 6 | FILE *fp; 7 | char c; 8 | 9 | fp = fopen("test.txt","r"); 10 | if (fp==NULL) { 11 | printf("Lathos sto anoigma tou arxeiou"); 12 | exit(0); 13 | } 14 | 15 | while (!feof(fp)) 16 | { 17 | c=fgetc(fp); 18 | printf("%c", c); 19 | } 20 | 21 | 22 | fclose(fp); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /lesson20/feof_binary.c: -------------------------------------------------------------------------------- 1 | /* feof_binary.c */ 2 | #include 3 | #include 4 | 5 | struct point { 6 | int x; 7 | int y; 8 | }; 9 | 10 | main() { 11 | FILE *fp; 12 | char c; 13 | int i; 14 | struct point data; 15 | 16 | 17 | fp = fopen("binarydata.dat","rb"); 18 | if (fp==NULL) { 19 | printf("Lathos sto anoigma tou arxeiou"); 20 | exit(0); 21 | } 22 | 23 | /* Diavasma apo to arxeio */ 24 | while (!feof(fp)) 25 | { 26 | if(fread(&data, sizeof(struct point), 1, fp)==1) 27 | printf("%d %d\n", data.x, data.y); 28 | } 29 | 30 | fclose(fp); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /lesson20/fgetc.c: -------------------------------------------------------------------------------- 1 | /* fgetc.c Diavasma kai ektipwsi enos arxeiou keimenoy */ 2 | #include 3 | #include 4 | 5 | main() { 6 | FILE *fp; 7 | char c; 8 | 9 | fp = fopen("test.txt","r"); 10 | if (fp==NULL) { 11 | printf("Lathos sto anoigma tou arxeiou"); 12 | exit(0); 13 | } 14 | 15 | while ((c=fgetc(fp))!=EOF) 16 | printf("%c", c); 17 | 18 | fclose(fp); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /lesson20/fprintf.c: -------------------------------------------------------------------------------- 1 | /* fprintf.cpp Grapsimo se arxeio */ 2 | #include 3 | #include 4 | 5 | main() { 6 | FILE *fp; 7 | int x=1; 8 | 9 | /* Anoigma arxeiou */ 10 | fp = fopen("test.txt","w"); 11 | if (fp==NULL) { 12 | printf("Lathos sto anoigma tou arxeiou"); 13 | exit(0); 14 | } 15 | 16 | /* Grapsimo se arxeio */ 17 | fprintf(fp, "Mia grammi\n"); 18 | fprintf(fp, "kai kapoioi arithmoi: %d %d %d", x, x*5, x/2); 19 | 20 | /* Kleisimo arxeiou */ 21 | fclose(fp); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /lesson20/fread.c: -------------------------------------------------------------------------------- 1 | /* fread.c Diavasma dyadikoy arxeioy */ 2 | #include 3 | #include 4 | 5 | #define N 10 6 | 7 | struct point { 8 | int x; 9 | int y; 10 | }; 11 | 12 | main() { 13 | FILE *fp; 14 | char c; 15 | int i; 16 | struct point data[N]; 17 | 18 | fp = fopen("binarydata.dat","rb"); 19 | if (fp==NULL) { 20 | printf("Lathos sto anoigma tou arxeiou"); 21 | exit(0); 22 | } 23 | 24 | /* Diavasma apo to arxeio */ 25 | fread(data, sizeof(struct point), N, fp); 26 | 27 | /* Ektypwsi stin othoni */ 28 | for (i=0; i 3 | #include 4 | #define N 100 5 | 6 | struct point { 7 | int x; 8 | int y; 9 | }; 10 | 11 | main() { 12 | FILE *fp; 13 | int i; 14 | int n; /* plithos eggrafwn */ 15 | struct point points[N]; /* eggrafes */ 16 | 17 | /* Diavasma apo to arxeio */ 18 | fp = fopen("points.txt","r"); 19 | if (fp==NULL) { 20 | printf("Lathos sto anoigma tou arxeiou"); 21 | exit(0); 22 | } 23 | 24 | fscanf(fp, "%d", &n); 25 | for (i=0; i 3 | #include 4 | 5 | #define N 10 6 | 7 | struct point { 8 | int x; 9 | int y; 10 | }; 11 | 12 | main() { 13 | FILE *fp; 14 | int i; 15 | struct point data; 16 | 17 | fp = fopen("binarydata.dat","rb"); 18 | if (fp==NULL) { 19 | printf("Lathos sto anoigma tou arxeiou"); 20 | exit(0); 21 | } 22 | 23 | printf("Dwse simeio(0-9): "); 24 | scanf("%d",&i); 25 | fseek(fp, sizeof(struct point)*i, SEEK_SET); 26 | fread(&data, sizeof(struct point), 1, fp); 27 | 28 | printf("Simeio %d: ", i); 29 | printf("%d %d\n", data.x, data.y); 30 | 31 | fclose(fp); 32 | } 33 | -------------------------------------------------------------------------------- /lesson20/ftell.c: -------------------------------------------------------------------------------- 1 | /* ftell.c */ 2 | #include 3 | #include 4 | 5 | main() { 6 | FILE *fp; 7 | char c; 8 | int i; 9 | 10 | fp = fopen("test.txt","r"); 11 | if (fp==NULL) { 12 | printf("Lathos sto anoigma tou arxeiou"); 13 | exit(0); 14 | } 15 | 16 | printf("\npos: %d\n", ftell(fp)); 17 | 18 | for (i=0; i<5; i++) 19 | printf("%c",fgetc(fp)); 20 | 21 | printf("\npos: %d\n", ftell(fp)); 22 | 23 | rewind(fp); 24 | 25 | printf("\npos: %d\n", ftell(fp)); 26 | 27 | while ((c=fgetc(fp))!=EOF) 28 | printf("%c", c); 29 | 30 | printf("\npos: %d\n", ftell(fp)); 31 | 32 | fclose(fp); 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /lesson20/fwrite.c: -------------------------------------------------------------------------------- 1 | /* fwrite.c Grafei enan pinaka domwn se arxeio */ 2 | #include 3 | #include 4 | 5 | #define N 10 6 | 7 | struct point { 8 | int x; 9 | int y; 10 | }; 11 | 12 | main() { 13 | FILE *fp; 14 | char c; 15 | int i; 16 | struct point data[N]; 17 | 18 | fp = fopen("binarydata.dat","wb"); 19 | if (fp==NULL) { 20 | printf("Lathos sto anoigma tou arxeiou"); 21 | exit(0); 22 | } 23 | 24 | /* Tyxaia Arxikopoiisi */ 25 | for (i=0; i 3 | #include 4 | 5 | main() { 6 | FILE *fp; 7 | char c; 8 | int i; 9 | 10 | fp = fopen("test.txt","r"); 11 | if (fp==NULL) { 12 | printf("Lathos sto anoigma tou arxeiou"); 13 | exit(0); 14 | } 15 | for (i=0; i<5; i++) 16 | printf("%c",fgetc(fp)); 17 | printf("\n"); 18 | 19 | rewind(fp); 20 | 21 | while ((c=fgetc(fp))!=EOF) 22 | printf("%c", c); 23 | 24 | fclose(fp); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /lesson20/temp.txt: -------------------------------------------------------------------------------- 1 | 0123 -------------------------------------------------------------------------------- /lesson21/askisi.3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double average(int n, ...); 5 | 6 | main() 7 | { 8 | printf("%.2lf\n", average(5,1,2,3,4,6)); 9 | } 10 | 11 | double average(int n, ...) 12 | { 13 | int i; 14 | double sum; 15 | va_list ptr; 16 | 17 | va_start(ptr,n); 18 | 19 | sum=0.0; 20 | for (i=0; i 2 | 3 | 4 | enum DATA_TYPE { INT, DOUBLE }; 5 | 6 | void selection_sort(void *pinakas, int N, enum DATA_TYPE d); 7 | void swap(void *a, void *b, enum DATA_TYPE d); 8 | 9 | 10 | main() 11 | { 12 | double pin[10]={1,4.2,7,5,6.1,8,6,2.8,3.5,3}; 13 | int i; 14 | 15 | selection_sort(pin, 10, DOUBLE); 16 | 17 | for (i=0; i<10; i++) 18 | printf("%.1lf ", pin[i]); 19 | } 20 | 21 | 22 | void selection_sort(void *pinakas, int N, enum DATA_TYPE d) 23 | { 24 | int pos, i, j; 25 | 26 | switch(d) 27 | { 28 | case INT: 29 | for (i=0; i 2 | #include 3 | #include 4 | 5 | 6 | void double_space(int *pin, int *N); 7 | void half_space(int *pin, int *N); 8 | void fill(int *pin, int N, int start, int finish); 9 | 10 | main() 11 | { 12 | int *p; 13 | int N=4; 14 | int i, choice; 15 | 16 | srand(time(0)); 17 | 18 | p = (int *)malloc(N*sizeof(int)); 19 | if(!p) 20 | { 21 | printf("Error Allocating Memory"); 22 | exit(0); 23 | } 24 | 25 | for (i=0; i=0 && start<=finish && finish<=N-1) 95 | { 96 | for (i=start; i<=finish; i++) 97 | pin[i]=rand()%100; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /lesson21/bits_in_struct.c: -------------------------------------------------------------------------------- 1 | /* bits_in_struct.c */ 2 | #include 3 | #include 4 | 5 | struct student 6 | { 7 | unsigned int active: 1; 8 | unsigned int type: 2; 9 | char name[80]; 10 | }; 11 | 12 | main() 13 | { 14 | struct student bob; 15 | 16 | bob.active=0; 17 | bob.type=2; 18 | strcpy(bob.name, "Bob"); 19 | 20 | printf("%d %d %s", bob.active, bob.type, bob.name); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lesson21/c21(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson21/c21(4sl).pdf -------------------------------------------------------------------------------- /lesson21/c21.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson21/c21.pdf -------------------------------------------------------------------------------- /lesson21/generic_pointer.c: -------------------------------------------------------------------------------- 1 | /* generic_pointer.c: Επίδειξη ενός δείκτη γενικού σκοπού */ 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int x = 4; 8 | double d = 1.1; 9 | 10 | void *p; 11 | 12 | p=&x; 13 | printf("%d", *(int *)p); 14 | 15 | p=&d; 16 | printf("\n%lf", *(double *)p); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /lesson21/realloc.c: -------------------------------------------------------------------------------- 1 | /* realloc.c */ 2 | 3 | #include 4 | #include 5 | 6 | main() 7 | { 8 | int n; 9 | int i; 10 | int *p; 11 | 12 | /* Desmeusi gia 4 akeraious */ 13 | n=4; 14 | p = (int *)malloc(n*sizeof(int)); 15 | if (!p) 16 | printf("Error allocating memory!"); 17 | 18 | /* Xrisi */ 19 | for (i=0; i 4 | #include 5 | 6 | int sum(int n, ...); 7 | 8 | main() 9 | { 10 | printf("%d\n", sum(5,1,2,3,4,5)); 11 | } 12 | 13 | int sum(int n, ...) 14 | { 15 | int i, s; 16 | va_list ptr; 17 | 18 | va_start(ptr,n); 19 | 20 | s=0; 21 | for (i=0; i 4 | 5 | struct point 6 | { 7 | int x; 8 | int y; 9 | }; 10 | 11 | int main() 12 | { 13 | struct point simeio; 14 | void *p = &simeio; 15 | 16 | simeio.x = 1; simeio.y = 2; 17 | 18 | printf("x=%d", *(int *)p); 19 | p+=sizeof(int); 20 | printf(" y=%d", *(int *)p); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /lesson21/voidptr_inc.c: -------------------------------------------------------------------------------- 1 | /* voidptr_inc.c */ 2 | 3 | #include 4 | 5 | enum DATA_TYPE { INT, DOUBLE, FLOAT }; 6 | 7 | void increase(void *number, enum DATA_TYPE d); 8 | 9 | int main() 10 | { 11 | int i=5; 12 | float f = 3.1; 13 | double d = 5.2; 14 | void *p; 15 | 16 | p = &i; 17 | increase(p, INT); 18 | printf("%d\n", *(int *)p); 19 | 20 | p = &f; 21 | increase(p, FLOAT); 22 | printf("%f\n", *(float *)p); 23 | 24 | p = &d; 25 | increase(p, DOUBLE); 26 | printf("%lf\n", *(double *)p); 27 | 28 | return 0; 29 | } 30 | 31 | void increase(void *number, enum DATA_TYPE d) 32 | { 33 | switch (d) 34 | { 35 | case INT: 36 | *(int *)number += 1; 37 | break; 38 | case FLOAT: 39 | *(float *)number += 1.0; 40 | break; 41 | case DOUBLE: 42 | *(double *)number += 1.0; 43 | } 44 | } -------------------------------------------------------------------------------- /lesson21/voidptr_printing.c: -------------------------------------------------------------------------------- 1 | /* voidptr_printing.c */ 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int x = 4; 8 | 9 | void *p = &x; 10 | 11 | //printf("%d", *p); // Δεν δουλεύει 12 | printf("Diefthinsi toy p: %p", &p); 13 | printf("\nDiefthinsi poy deixnei o p: %p", p); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /lesson22/askisi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define BITS 8 4 | 5 | int LSB(unsigned char byte); 6 | int MSB(unsigned char byte); 7 | void bits_print(unsigned char byte); 8 | int get_bit(int pos, unsigned char byte); 9 | 10 | main() 11 | { 12 | unsigned char byte = 52; 13 | bits_print(byte); 14 | printf("\nLSB=%d", LSB(byte)); 15 | printf("\nMSB=%d", MSB(byte)); 16 | } 17 | 18 | int LSB(unsigned char byte) 19 | { 20 | unsigned char mask = 1; 21 | 22 | return byte & mask; 23 | } 24 | 25 | int MSB(unsigned char byte) 26 | { 27 | unsigned char mask = 1; 28 | 29 | return (byte >> BITS - 1) & mask; 30 | } 31 | 32 | void bits_print(unsigned char byte) 33 | { 34 | int i; 35 | for (i=0; i 2 | 3 | #define BITS 8 4 | 5 | void rotate(unsigned char *byte); 6 | void bits_print(unsigned char byte); 7 | int get_bit(int pos, unsigned char byte); 8 | 9 | main() 10 | { 11 | unsigned char byte = 143; 12 | 13 | bits_print(byte); 14 | printf("\n"); 15 | rotate(&byte); 16 | bits_print(byte); 17 | } 18 | 19 | 20 | void rotate(unsigned char *byte) 21 | { 22 | int bit; 23 | unsigned char mask = 1; 24 | 25 | bit = (*byte)%2; 26 | 27 | *byte = *byte >> 1; 28 | 29 | if (bit==1) 30 | *byte = (mask << BITS-1) | *byte; 31 | 32 | } 33 | 34 | void bits_print(unsigned char byte) 35 | { 36 | int i; 37 | for (i=0; i 2 | #include 3 | #include 4 | #define RECS 10000 5 | 6 | struct point { 7 | unsigned int visibility : 1; 8 | unsigned int color : 6; 9 | int x; 10 | int y; 11 | }; 12 | 13 | main() 14 | { 15 | FILE *fp; 16 | int recs=RECS; 17 | struct point p; 18 | int i; 19 | 20 | fp = fopen("test.txt","wb+"); 21 | if (!fp) 22 | { 23 | printf("Error opening file"); 24 | exit(0); 25 | } 26 | 27 | fwrite(&recs,sizeof(int),1,fp); 28 | 29 | srand(time(0)); 30 | for (i=0; i 4 | 5 | #define BITS 8 6 | 7 | int get_bit(int pos, unsigned char byte); 8 | void bits_print(unsigned char byte); 9 | 10 | int main() 11 | { 12 | unsigned char byte = 53; 13 | 14 | printf("\n%d=",byte); 15 | bits_print(byte); 16 | printf("\n%d", get_bit(2,byte)); 17 | 18 | return 0; 19 | } 20 | 21 | int get_bit(int pos, unsigned char byte) 22 | { 23 | int i; 24 | 25 | for (i=0; i 4 | 5 | #define BITS 8 6 | 7 | int get_bit(int pos, unsigned char byte); 8 | void bits_print(unsigned char byte); 9 | 10 | int main() 11 | { 12 | unsigned char byte = 53; 13 | 14 | printf("\n%d=",byte); 15 | bits_print(byte); 16 | printf("\n%d", get_bit(2,byte)); 17 | 18 | return 0; 19 | } 20 | 21 | int get_bit(int pos, unsigned char byte) 22 | { 23 | return (byte >> BITS-1-pos)%2; 24 | } 25 | 26 | void bits_print(unsigned char byte) 27 | { 28 | int i; 29 | for (i=0; i 4 | 5 | #define BITS 8 6 | 7 | int get_bit(int pos, unsigned char byte); 8 | void bits_print(unsigned char byte); 9 | 10 | int main() 11 | { 12 | unsigned char byte = 53; 13 | 14 | printf("\n%d=",byte); 15 | bits_print(byte); 16 | 17 | return 0; 18 | } 19 | 20 | int get_bit(int pos, unsigned char byte) 21 | { 22 | return (byte >> BITS-1-pos)%2; 23 | } 24 | 25 | void bits_print(unsigned char byte) 26 | { 27 | int i; 28 | for (i=0; i 4 | 5 | #define BITS 8 6 | 7 | int main() 8 | { 9 | unsigned char byte = 254; 10 | int bits[BITS]; 11 | int i; 12 | 13 | for (i=0; i 4 | 5 | #define BITS 8 6 | 7 | int get_bit(int pos, unsigned char byte); 8 | void set_bit(unsigned char *byte, int pos, int val); 9 | void bits_print(unsigned char byte); 10 | 11 | int main() 12 | { 13 | unsigned char byte = 53; 14 | 15 | bits_print(byte); 16 | set_bit(&byte,2,0); 17 | printf("\n"); 18 | bits_print(byte); 19 | printf("\n"); 20 | set_bit(&byte,0,1); 21 | printf("\n"); 22 | bits_print(byte); 23 | 24 | return 0; 25 | } 26 | 27 | int get_bit(int pos, unsigned char byte) 28 | { 29 | return (byte >> BITS-1-pos) & 1; 30 | } 31 | 32 | void set_bit(unsigned char *byte, int pos, int val) 33 | { 34 | unsigned char mask = 1; 35 | 36 | if (val==0) 37 | *byte = ~(mask << BITS-1-pos) & *byte; 38 | else 39 | *byte = (mask << BITS-1-pos) | *byte; 40 | } 41 | 42 | void bits_print(unsigned char byte) 43 | { 44 | int i; 45 | for (i=0; i 4 | 5 | #define N 3 6 | 7 | int inc(int x); 8 | int dec(int x); 9 | int half(int x); 10 | 11 | main() 12 | { 13 | int (*ptr [N])(int); 14 | int i; 15 | 16 | ptr[0]=inc; 17 | ptr[1]=dec; 18 | ptr[2]=half; 19 | 20 | for (i=0; i 2 | #include 3 | 4 | typedef double (*pf) (double); 5 | 6 | double f(double x); 7 | double g(double x); 8 | 9 | void root(pf ptr, double a, double b); 10 | 11 | main() 12 | { 13 | root(g, -1.0, 0.0); 14 | } 15 | 16 | double f(double x) 17 | { 18 | return 2*x; 19 | } 20 | 21 | double g(double x) 22 | { 23 | return sin(x)+1; 24 | } 25 | 26 | void root(pf ptr, double a, double b) 27 | { 28 | while(1) 29 | { 30 | if (fabs(ptr(a))<=0.000005) 31 | { 32 | printf("H riza einai %.3lf", a); 33 | break; 34 | } 35 | else if (fabs(ptr(b))<=0.000005) 36 | { 37 | printf("H riza einai %.3lf", b); 38 | break; 39 | } 40 | else if (ptr(a)*ptr(b)>0) 41 | { 42 | printf("Pithanon den yparxei riza"); 43 | break; 44 | } 45 | else //eterosimoi 46 | { 47 | if (fabs(ptr((a+b)/2))<=0.000005) 48 | { 49 | printf("H riza einai %.3lf", (a+b)/2); 50 | break; 51 | } 52 | if (ptr(a)*ptr((a+b)/2)>0) 53 | { 54 | a=(a+b)/2; 55 | } 56 | else 57 | { 58 | b=(a+b)/2; 59 | } 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /lesson23/askisi2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SIZE 6 4 | 5 | typedef int (*pf) (int, int); 6 | 7 | int compare_asc(int a, int b); 8 | int compare_desc(int a, int b); 9 | 10 | void insertion_sort(int *pinakas, int N, pf comp); 11 | void swap(int *a, int *b); 12 | 13 | main() 14 | { 15 | int pin[]={1,5,3,2,8,7}; 16 | int i; 17 | 18 | insertion_sort(pin, SIZE, compare_desc); 19 | 20 | for (i=0; i=1; j--) 45 | { 46 | if (comp(pinakas[j], pinakas[j-1])==-1) 47 | swap(&pinakas[j], &pinakas[j-1]); 48 | else 49 | break; 50 | } 51 | } 52 | } 53 | 54 | void swap(int *a, int *b) 55 | { 56 | int k=*a; 57 | *a=*b; 58 | *b=k; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /lesson23/c23(sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson23/c23(sl).pdf -------------------------------------------------------------------------------- /lesson23/c23.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson23/c23.pdf -------------------------------------------------------------------------------- /lesson23/class.c: -------------------------------------------------------------------------------- 1 | /* class.c */ 2 | 3 | #include 4 | 5 | typedef void (*pf) (int, int); 6 | 7 | void print(int x, int y); 8 | 9 | struct complex { 10 | int x; 11 | int y; 12 | pf print; 13 | }; 14 | 15 | main() 16 | { 17 | struct complex a,b; 18 | a.x=1; 19 | a.y=1; 20 | a.print=print; 21 | b.x=1; 22 | b.y=1; 23 | b.print=print; 24 | 25 | a.print(a.x,a.y); 26 | a.print(b.x,b.y); 27 | } 28 | 29 | void print(int x, int y) 30 | { 31 | printf("(%d,%d)",x,y); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /lesson23/function_with_arg_pointer.c: -------------------------------------------------------------------------------- 1 | /* function_with_arg_pointer.c */ 2 | 3 | #include 4 | 5 | int inc(int x); 6 | int dec(int x); 7 | int half(int x); 8 | 9 | int func(int (*ptr1)(int), int arg); 10 | 11 | main() 12 | { 13 | printf("result=%d", func(inc, 2)); 14 | } 15 | 16 | int inc(int x) 17 | { 18 | return ++x; 19 | } 20 | 21 | int dec(int x) 22 | { 23 | return --x; 24 | } 25 | 26 | int half(int x) 27 | { 28 | return x/2; 29 | } 30 | 31 | int func(int (*ptr1)(int), int arg) 32 | { 33 | return ptr1(arg); 34 | } 35 | -------------------------------------------------------------------------------- /lesson23/perror.c: -------------------------------------------------------------------------------- 1 | /* perror.c */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int *p; 9 | 10 | printf("Enarksi programmatos...\n"); 11 | 12 | p=(int *)malloc(sizeof(int)*100000000000); 13 | if (!p) 14 | { 15 | perror(0); 16 | exit(EXIT_FAILURE); 17 | } 18 | printf("Telos programmatos\n"); 19 | free(p); 20 | exit(EXIT_SUCCESS); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lesson23/pointer_to_diff_functions.c: -------------------------------------------------------------------------------- 1 | /* pointer_to_diff_functions.c */ 2 | 3 | #include 4 | 5 | typedef int (*pf) (int, int); 6 | 7 | int add(int a, int b); 8 | int sub(int a, int b); 9 | int mult(int a, int b); 10 | 11 | main() 12 | { 13 | int x,y, choice; 14 | pf ptr; 15 | 16 | printf("Dwse x: "); 17 | scanf("%d", &x); 18 | printf("Dwse y: "); 19 | scanf("%d", &y); 20 | printf("Dwse sinartisi (1-add, 2-sub, 3-mult): "); 21 | scanf("%d", &choice); 22 | 23 | switch(choice) 24 | { 25 | case 1: 26 | ptr=add; 27 | break; 28 | case 2: 29 | ptr=sub; 30 | break; 31 | case 3: 32 | ptr=mult; 33 | } 34 | 35 | printf("result=%d", ptr(x,y)); 36 | } 37 | 38 | int add(int a, int b) 39 | { 40 | return a+b; 41 | } 42 | 43 | int sub(int a, int b) 44 | { 45 | return a-b; 46 | } 47 | 48 | int mult(int a, int b) 49 | { 50 | return a*b; 51 | } 52 | -------------------------------------------------------------------------------- /lesson23/pointer_to_function.c: -------------------------------------------------------------------------------- 1 | /* pointer_to_function.c Deiktis se sinartisi */ 2 | 3 | #include 4 | 5 | int sum(int a, int b); 6 | 7 | main() 8 | { 9 | int (*ptr)(int, int); 10 | 11 | ptr=sum; 12 | 13 | printf("%d", ptr(1,2)); 14 | } 15 | 16 | int sum(int a, int b) 17 | { 18 | return a+b; 19 | } -------------------------------------------------------------------------------- /lesson23/typedef_pointer_function.c: -------------------------------------------------------------------------------- 1 | /* typedef_pointer_function.c */ 2 | 3 | #include 4 | 5 | typedef int (*pf) (int, int); 6 | 7 | int add(int a, int b); 8 | int sub(int a, int b); 9 | int mult(int a, int b); 10 | 11 | main() 12 | { 13 | int x,y, choice; 14 | pf ptr; 15 | 16 | printf("Dwse x: "); 17 | scanf("%d", &x); 18 | printf("Dwse y: "); 19 | scanf("%d", &y); 20 | printf("Dwse sinartisi (1-add, 2-sub, 3-mult): "); 21 | scanf("%d", &choice); 22 | 23 | switch(choice) 24 | { 25 | case 1: 26 | ptr=add; 27 | break; 28 | case 2: 29 | ptr=sub; 30 | break; 31 | case 3: 32 | ptr=mult; 33 | } 34 | 35 | printf("result=%d", ptr(x,y)); 36 | } 37 | 38 | int add(int a, int b) 39 | { 40 | return a+b; 41 | } 42 | 43 | int sub(int a, int b) 44 | { 45 | return a-b; 46 | } 47 | 48 | int mult(int a, int b) 49 | { 50 | return a*b; 51 | } 52 | -------------------------------------------------------------------------------- /lesson24/askisi1.c: -------------------------------------------------------------------------------- 1 | /* askisi1.c */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | FILE *fp; 9 | 10 | printf("Enarksi programmatos...\n"); 11 | 12 | fp=fopen("bourdes.txt","r"); 13 | if (!fp) 14 | { 15 | fprintf(stderr, "ERROR %d\n", errno); 16 | perror(0); 17 | exit(EXIT_FAILURE); 18 | } 19 | printf("Telos programmatos\n"); 20 | exit(EXIT_SUCCESS); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lesson24/c24(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson24/c24(4sl).pdf -------------------------------------------------------------------------------- /lesson24/c24.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson24/c24.pdf -------------------------------------------------------------------------------- /lesson24/errno.c: -------------------------------------------------------------------------------- 1 | /* errno.c */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int *p; 9 | 10 | printf("Enarksi programmatos...\n"); 11 | 12 | p=(int *)malloc(sizeof(int)*100000000000); 13 | if (!p) 14 | { 15 | fprintf(stderr, "errno: %d\n", errno); 16 | fprintf(stderr, "Adynamia Desmeusis mnimis!\n"); 17 | exit(EXIT_FAILURE); 18 | } 19 | printf("Telos programmatos\n"); 20 | free(p); 21 | exit(EXIT_SUCCESS); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /lesson24/stderr.c: -------------------------------------------------------------------------------- 1 | /* stderr.c */ 2 | #include 3 | #include 4 | 5 | main() 6 | { 7 | int *p; 8 | 9 | printf("Enarksi programmatos...\n"); 10 | 11 | p=(int *)malloc(sizeof(int)*100000000000); 12 | if (!p) 13 | { 14 | fprintf(stderr, "Adynamia Desmeusis mnimis!\n"); 15 | exit(0); 16 | } 17 | printf("Telos programmatos\n"); 18 | free(p); 19 | } 20 | -------------------------------------------------------------------------------- /lesson24/stderr2.c: -------------------------------------------------------------------------------- 1 | /* stderr2.c */ 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int *p; 8 | 9 | printf("Enarksi programmatos...\n"); 10 | 11 | p=(int *)malloc(sizeof(int)*100000000000); 12 | if (!p) 13 | { 14 | fprintf(stderr, "Adynamia Desmeusis mnimis!\n"); 15 | exit(EXIT_FAILURE); 16 | } 17 | printf("Telos programmatos\n"); 18 | free(p); 19 | exit(EXIT_SUCCESS); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /lesson24/strerror.c: -------------------------------------------------------------------------------- 1 | /* strerror.c */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int *p; 9 | 10 | printf("Enarksi programmatos...\n"); 11 | 12 | p=(int *)malloc(sizeof(int)*100000000000); 13 | if (!p) 14 | { 15 | fprintf(stderr, "ERROR %d:%s\n", errno, strerror(errno)); 16 | exit(EXIT_FAILURE); 17 | } 18 | printf("Telos programmatos\n"); 19 | free(p); 20 | exit(EXIT_SUCCESS); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /lesson25/c25(4sl).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/c25(4sl).pdf -------------------------------------------------------------------------------- /lesson25/c25.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/c25.pdf -------------------------------------------------------------------------------- /lesson25/macro_function.c: -------------------------------------------------------------------------------- 1 | /* macro_function.c */ 2 | 3 | #include 4 | 5 | #define half(x) ((x)/2) 6 | 7 | main() 8 | { 9 | int i=5; 10 | float f=2.2; 11 | 12 | printf("half(%d)=%d\n", i, half(i)); 13 | printf("half(%.1f)=%.1f\n", f, half(f)); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lesson25/macro_function2.c: -------------------------------------------------------------------------------- 1 | /* macro_function2.c */ 2 | 3 | #include 4 | 5 | #define sum(x,y) ((x)+(y)) 6 | 7 | main() 8 | { 9 | int v = sum(5,5*3); 10 | printf("sum=%d\n", v); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /lesson25/macro_function3.c: -------------------------------------------------------------------------------- 1 | /* macro_function3.c */ 2 | 3 | #include 4 | 5 | #define out(x) printf(#x) 6 | 7 | main() 8 | { 9 | out(This is a string); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /lesson25/macro_function4.c: -------------------------------------------------------------------------------- 1 | /* macro_function4.c */ 2 | 3 | #include 4 | 5 | #define v(x) v ## x 6 | 7 | main() 8 | { 9 | int i, v1=1, v2=2; 10 | 11 | printf("%d", v(1)); 12 | printf("%d", v(2)); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /lesson25/project1/Makefile.win: -------------------------------------------------------------------------------- 1 | # Project: project1 2 | # Makefile created by Dev-C++ 5.11 3 | 4 | CPP = g++.exe 5 | CC = gcc.exe 6 | WINDRES = windres.exe 7 | OBJ = h.o h1.o h2.o main.o 8 | LINKOBJ = h.o h1.o h2.o main.o 9 | LIBS = -L"C:/Dev-Cpp/MinGW64/lib" -L"C:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc 10 | INCS = -I"C:/Dev-Cpp/MinGW64/include" -I"C:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" 11 | CXXINCS = -I"C:/Dev-Cpp/MinGW64/include" -I"C:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" 12 | BIN = project1.exe 13 | CXXFLAGS = $(CXXINCS) 14 | CFLAGS = $(INCS) 15 | RM = rm.exe -f 16 | 17 | .PHONY: all all-before all-after clean clean-custom 18 | 19 | all: all-before $(BIN) all-after 20 | 21 | clean: clean-custom 22 | ${RM} $(OBJ) $(BIN) 23 | 24 | $(BIN): $(OBJ) 25 | $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS) 26 | 27 | h.o: h.c 28 | $(CPP) -c h.c -o h.o $(CXXFLAGS) 29 | 30 | h1.o: h1.c 31 | $(CPP) -c h1.c -o h1.o $(CXXFLAGS) 32 | 33 | h2.o: h2.c 34 | $(CPP) -c h2.c -o h2.o $(CXXFLAGS) 35 | 36 | main.o: main.c 37 | $(CPP) -c main.c -o main.o $(CXXFLAGS) 38 | -------------------------------------------------------------------------------- /lesson25/project1/h.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "h.h" 3 | 4 | void h() 5 | { 6 | struct temp t; 7 | printf("in h\n"); 8 | } 9 | -------------------------------------------------------------------------------- /lesson25/project1/h.h: -------------------------------------------------------------------------------- 1 | 2 | void h(); 3 | 4 | struct temp { 5 | int x; 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /lesson25/project1/h.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project1/h.o -------------------------------------------------------------------------------- /lesson25/project1/h1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "h1.h" 3 | 4 | void h1() 5 | { 6 | printf("in h1\n"); 7 | h(); 8 | } 9 | -------------------------------------------------------------------------------- /lesson25/project1/h1.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "h.h" 4 | 5 | 6 | void h1(); 7 | 8 | -------------------------------------------------------------------------------- /lesson25/project1/h1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project1/h1.o -------------------------------------------------------------------------------- /lesson25/project1/h2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "h2.h" 3 | 4 | void h2() 5 | { 6 | printf("in h2\n"); 7 | h(); 8 | } 9 | -------------------------------------------------------------------------------- /lesson25/project1/h2.h: -------------------------------------------------------------------------------- 1 | 2 | #include "h.h" 3 | 4 | 5 | void h2(); 6 | 7 | 8 | -------------------------------------------------------------------------------- /lesson25/project1/h2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project1/h2.o -------------------------------------------------------------------------------- /lesson25/project1/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "h1.h" 3 | #include "h2.h" 4 | 5 | main() 6 | { 7 | h1(); 8 | h2(); 9 | } 10 | -------------------------------------------------------------------------------- /lesson25/project1/project1.dev: -------------------------------------------------------------------------------- 1 | [Project] 2 | FileName=project1.dev 3 | Name=project1 4 | Type=1 5 | Ver=2 6 | ObjFiles= 7 | Includes= 8 | Libs= 9 | PrivateResource= 10 | ResourceIncludes= 11 | MakeIncludes= 12 | Compiler= 13 | CppCompiler= 14 | Linker= 15 | IsCpp=1 16 | Icon= 17 | ExeOutput= 18 | ObjectOutput= 19 | LogOutput= 20 | LogOutputEnabled=0 21 | OverrideOutput=0 22 | OverrideOutputName= 23 | HostApplication= 24 | UseCustomMakefile=0 25 | CustomMakefile= 26 | CommandLine= 27 | Folders= 28 | IncludeVersionInfo=0 29 | SupportXPThemes=0 30 | CompilerSet=0 31 | CompilerSettings=0000000000000000000000000 32 | UnitCount=7 33 | 34 | [VersionInfo] 35 | Major=1 36 | Minor=0 37 | Release=0 38 | Build=0 39 | LanguageID=1033 40 | CharsetID=1252 41 | CompanyName= 42 | FileVersion= 43 | FileDescription=Developed using the Dev-C++ IDE 44 | InternalName= 45 | LegalCopyright= 46 | LegalTrademarks= 47 | OriginalFilename= 48 | ProductName= 49 | ProductVersion= 50 | AutoIncBuildNr=0 51 | SyncProduct=1 52 | 53 | [Unit1] 54 | FileName=h.c 55 | CompileCpp=1 56 | Folder= 57 | Compile=1 58 | Link=1 59 | Priority=1000 60 | OverrideBuildCmd=0 61 | BuildCmd= 62 | 63 | [Unit2] 64 | FileName=h.h 65 | CompileCpp=1 66 | Folder= 67 | Compile=1 68 | Link=1 69 | Priority=1000 70 | OverrideBuildCmd=0 71 | BuildCmd= 72 | 73 | [Unit3] 74 | FileName=h1.c 75 | CompileCpp=1 76 | Folder= 77 | Compile=1 78 | Link=1 79 | Priority=1000 80 | OverrideBuildCmd=0 81 | BuildCmd= 82 | 83 | [Unit4] 84 | FileName=h1.h 85 | CompileCpp=1 86 | Folder= 87 | Compile=1 88 | Link=1 89 | Priority=1000 90 | OverrideBuildCmd=0 91 | BuildCmd= 92 | 93 | [Unit5] 94 | FileName=h2.c 95 | CompileCpp=1 96 | Folder= 97 | Compile=1 98 | Link=1 99 | Priority=1000 100 | OverrideBuildCmd=0 101 | BuildCmd= 102 | 103 | [Unit6] 104 | FileName=h2.h 105 | CompileCpp=1 106 | Folder= 107 | Compile=1 108 | Link=1 109 | Priority=1000 110 | OverrideBuildCmd=0 111 | BuildCmd= 112 | 113 | [Unit7] 114 | FileName=main.c 115 | CompileCpp=1 116 | Folder= 117 | Compile=1 118 | Link=1 119 | Priority=1000 120 | OverrideBuildCmd=0 121 | BuildCmd= 122 | 123 | -------------------------------------------------------------------------------- /lesson25/project1/project1.layout: -------------------------------------------------------------------------------- 1 | [Editor_0] 2 | CursorCol=15 3 | CursorRow=6 4 | TopLine=1 5 | LeftChar=1 6 | [Editors] 7 | Order=6,0,1 8 | Focused=1 9 | [Editor_1] 10 | CursorCol=3 11 | CursorRow=6 12 | TopLine=1 13 | LeftChar=1 14 | [Editor_6] 15 | CursorCol=1 16 | CursorRow=1 17 | TopLine=1 18 | LeftChar=1 19 | -------------------------------------------------------------------------------- /lesson25/project2/Makefile.win: -------------------------------------------------------------------------------- 1 | # Project: project2.dev 2 | # Makefile created by Dev-C++ 5.11 3 | 4 | CPP = g++.exe 5 | CC = gcc.exe 6 | WINDRES = windres.exe 7 | OBJ = h.o h1.o h2.o main.o 8 | LINKOBJ = h.o h1.o h2.o main.o 9 | LIBS = -L"C:/Dev-Cpp/MinGW64/lib" -L"C:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc 10 | INCS = -I"C:/Dev-Cpp/MinGW64/include" -I"C:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" 11 | CXXINCS = -I"C:/Dev-Cpp/MinGW64/include" -I"C:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" 12 | BIN = project2.exe 13 | CXXFLAGS = $(CXXINCS) 14 | CFLAGS = $(INCS) 15 | RM = rm.exe -f 16 | 17 | .PHONY: all all-before all-after clean clean-custom 18 | 19 | all: all-before $(BIN) all-after 20 | 21 | clean: clean-custom 22 | ${RM} $(OBJ) $(BIN) 23 | 24 | $(BIN): $(OBJ) 25 | $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS) 26 | 27 | h.o: h.c 28 | $(CPP) -c h.c -o h.o $(CXXFLAGS) 29 | 30 | h1.o: h1.c 31 | $(CPP) -c h1.c -o h1.o $(CXXFLAGS) 32 | 33 | h2.o: h2.c 34 | $(CPP) -c h2.c -o h2.o $(CXXFLAGS) 35 | 36 | main.o: main.c 37 | $(CPP) -c main.c -o main.o $(CXXFLAGS) 38 | -------------------------------------------------------------------------------- /lesson25/project2/askisi1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define MALLOC(p,t,n) p=(t *)malloc((n)*sizeof(t)); \ 6 | if (!p) { \ 7 | fprintf(stderr, "Error Allocating Memory"); \ 8 | exit(errno); \ 9 | } 10 | 11 | main() 12 | { 13 | int *pin; 14 | int i; 15 | 16 | MALLOC(pin,int,5); 17 | 18 | for (i=0; i<5; i++) 19 | { 20 | pin[i]=i*i; 21 | printf("%d ",pin[i]); 22 | } 23 | 24 | free(pin); 25 | } 26 | -------------------------------------------------------------------------------- /lesson25/project2/askisi1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project2/askisi1.exe -------------------------------------------------------------------------------- /lesson25/project2/askisi2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define FOPEN(fp,filename,mode) fp=fopen(#filename, #mode); \ 6 | if (!fp) { \ 7 | fprintf(stderr, "Error Opening File"); \ 8 | exit(errno); \ 9 | } 10 | 11 | main() 12 | { 13 | FILE *fp; 14 | 15 | FOPEN(fp,file.txt,r); 16 | 17 | fclose(fp); 18 | } 19 | -------------------------------------------------------------------------------- /lesson25/project2/askisi2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project2/askisi2.exe -------------------------------------------------------------------------------- /lesson25/project2/h.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "h.h" 3 | 4 | void h(void) 5 | { 6 | struct temp t; 7 | printf("in h\n"); 8 | } 9 | -------------------------------------------------------------------------------- /lesson25/project2/h.h: -------------------------------------------------------------------------------- 1 | #ifndef H_H 2 | #define H_H 3 | 4 | void h(void); 5 | 6 | struct temp { 7 | int x; 8 | }; 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /lesson25/project2/h.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project2/h.o -------------------------------------------------------------------------------- /lesson25/project2/h1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "h1.h" 3 | 4 | void h1(void) 5 | { 6 | printf("in h1\n"); 7 | h(); 8 | } 9 | -------------------------------------------------------------------------------- /lesson25/project2/h1.h: -------------------------------------------------------------------------------- 1 | #ifndef H1_H 2 | #define H1_H 3 | 4 | #include "h.h" 5 | 6 | void h1(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /lesson25/project2/h1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project2/h1.o -------------------------------------------------------------------------------- /lesson25/project2/h2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "h2.h" 3 | 4 | void h2(void) 5 | { 6 | printf("in h2\n"); 7 | h(); 8 | } 9 | -------------------------------------------------------------------------------- /lesson25/project2/h2.h: -------------------------------------------------------------------------------- 1 | #ifndef H2_H 2 | #define H2_H 3 | 4 | #include "h.h" 5 | 6 | void h2(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /lesson25/project2/h2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project2/h2.o -------------------------------------------------------------------------------- /lesson25/project2/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "h1.h" 3 | #include "h2.h" 4 | 5 | main() 6 | { 7 | h1(); 8 | h2(); 9 | } 10 | -------------------------------------------------------------------------------- /lesson25/project2/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project2/main.o -------------------------------------------------------------------------------- /lesson25/project2/project2.dev: -------------------------------------------------------------------------------- 1 | [Project] 2 | FileName=project2.dev 3 | Name=project2.dev 4 | Type=1 5 | Ver=2 6 | ObjFiles= 7 | Includes= 8 | Libs= 9 | PrivateResource= 10 | ResourceIncludes= 11 | MakeIncludes= 12 | Compiler= 13 | CppCompiler= 14 | Linker= 15 | IsCpp=1 16 | Icon= 17 | ExeOutput= 18 | ObjectOutput= 19 | LogOutput= 20 | LogOutputEnabled=0 21 | OverrideOutput=0 22 | OverrideOutputName= 23 | HostApplication= 24 | UseCustomMakefile=0 25 | CustomMakefile= 26 | CommandLine= 27 | Folders= 28 | IncludeVersionInfo=0 29 | SupportXPThemes=0 30 | CompilerSet=0 31 | CompilerSettings=0000000000000000000000000 32 | UnitCount=7 33 | 34 | [VersionInfo] 35 | Major=1 36 | Minor=0 37 | Release=0 38 | Build=0 39 | LanguageID=1033 40 | CharsetID=1252 41 | CompanyName= 42 | FileVersion= 43 | FileDescription=Developed using the Dev-C++ IDE 44 | InternalName= 45 | LegalCopyright= 46 | LegalTrademarks= 47 | OriginalFilename= 48 | ProductName= 49 | ProductVersion= 50 | AutoIncBuildNr=0 51 | SyncProduct=1 52 | 53 | [Unit1] 54 | FileName=h.h 55 | CompileCpp=1 56 | Folder= 57 | Compile=1 58 | Link=1 59 | Priority=1000 60 | OverrideBuildCmd=0 61 | BuildCmd= 62 | 63 | [Unit2] 64 | FileName=h1.h 65 | CompileCpp=1 66 | Folder= 67 | Compile=1 68 | Link=1 69 | Priority=1000 70 | OverrideBuildCmd=0 71 | BuildCmd= 72 | 73 | [Unit3] 74 | FileName=h2.h 75 | CompileCpp=1 76 | Folder= 77 | Compile=1 78 | Link=1 79 | Priority=1000 80 | OverrideBuildCmd=0 81 | BuildCmd= 82 | 83 | [Unit4] 84 | FileName=h.c 85 | CompileCpp=1 86 | Folder= 87 | Compile=1 88 | Link=1 89 | Priority=1000 90 | OverrideBuildCmd=0 91 | BuildCmd= 92 | 93 | [Unit5] 94 | FileName=h1.c 95 | CompileCpp=1 96 | Folder= 97 | Compile=1 98 | Link=1 99 | Priority=1000 100 | OverrideBuildCmd=0 101 | BuildCmd= 102 | 103 | [Unit6] 104 | FileName=h2.c 105 | CompileCpp=1 106 | Folder= 107 | Compile=1 108 | Link=1 109 | Priority=1000 110 | OverrideBuildCmd=0 111 | BuildCmd= 112 | 113 | [Unit7] 114 | FileName=main.c 115 | CompileCpp=1 116 | Folder= 117 | Compile=1 118 | Link=1 119 | Priority=1000 120 | OverrideBuildCmd=0 121 | BuildCmd= 122 | 123 | -------------------------------------------------------------------------------- /lesson25/project2/project2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/C-programming/6bbb29e7233c91c22e975ed961760300839aaea1/lesson25/project2/project2.exe -------------------------------------------------------------------------------- /lesson25/project2/project2.layout: -------------------------------------------------------------------------------- 1 | [Editor_0] 2 | CursorCol=1 3 | CursorRow=1 4 | TopLine=1 5 | LeftChar=1 6 | [Editors] 7 | Order=6,0,1,2 8 | Focused=6 9 | [Editor_6] 10 | CursorCol=2 11 | CursorRow=9 12 | TopLine=1 13 | LeftChar=1 14 | [Editor_3] 15 | CursorCol=1 16 | CursorRow=1 17 | TopLine=1 18 | LeftChar=1 19 | [Editor_1] 20 | CursorCol=1 21 | CursorRow=1 22 | TopLine=1 23 | LeftChar=1 24 | [Editor_2] 25 | CursorCol=1 26 | CursorRow=1 27 | TopLine=1 28 | LeftChar=1 29 | --------------------------------------------------------------------------------