diff --git a/helloworld/.c b/helloworld/.c new file mode 100644 index 0000000..cb9c3d9 --- /dev/null +++ b/helloworld/.c @@ -0,0 +1,8 @@ +1: /* 02L01.c: This is my first C program */ +2: #include +3: +4: main() +5: { +6: printf ("Howdy, neighbor! This is my first C program.\n"); +7: return 0; +8: } \ No newline at end of file diff --git a/helloworld/H2_E2.c b/helloworld/H2_E2.c new file mode 100644 index 0000000..9129de2 --- /dev/null +++ b/helloworld/H2_E2.c @@ -0,0 +1,8 @@ +#include +#include + +void main() { + printf("It's fun to write my own program in C.\n"); + exit(0); + +} \ No newline at end of file diff --git a/helloworld/H2_E3.c b/helloworld/H2_E3.c new file mode 100644 index 0000000..256ecd2 --- /dev/null +++ b/helloworld/H2_E3.c @@ -0,0 +1,7 @@ +#include +#include + +void main() { + printf("\nHowdy, neighbor!\nThis is my first C program.\n"); + return 0; +} \ No newline at end of file diff --git a/helloworld/H3_E5.c b/helloworld/H3_E5.c new file mode 100644 index 0000000..5b97dcf --- /dev/null +++ b/helloworld/H3_E5.c @@ -0,0 +1,10 @@ +#include +/* This function multiplicate two integers and returns the result */ +int integer_mult(int x, int y) { + return x * y; +} + +int main() { + printf("3 times 5 is %d.\n", integer_mult(3, 5)); + return 0; +} \ No newline at end of file diff --git a/helloworld/H4_E1.c b/helloworld/H4_E1.c new file mode 100644 index 0000000..ade56cb --- /dev/null +++ b/helloworld/H4_E1.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("The numeric value of Z is: %d, the same of z is: %d.", 'Z', 'z'); + return 0; +} \ No newline at end of file diff --git a/helloworld/H4_E2.c b/helloworld/H4_E2.c new file mode 100644 index 0000000..a131fd0 --- /dev/null +++ b/helloworld/H4_E2.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("The ASCII value of 72 is character: %c, the 104 is character: %c.", 72, 104); + return 0; +} \ No newline at end of file diff --git a/helloworld/H4_E4.c b/helloworld/H4_E4.c new file mode 100644 index 0000000..8ec0ebb --- /dev/null +++ b/helloworld/H4_E4.c @@ -0,0 +1,7 @@ +#include + +int main() { + double dbl_num = 123.456; + printf("Floating is: %f, scientific is: %e.", dbl_num, dbl_num); + return 0; +} \ No newline at end of file diff --git a/helloworld/H4_E5.c b/helloworld/H4_E5.c new file mode 100644 index 0000000..7c4986c --- /dev/null +++ b/helloworld/H4_E5.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("The numeric value of '\n' is: %d.", '\n'); + return 0; +} \ No newline at end of file diff --git a/helloworld/H5_E1.c b/helloworld/H5_E1.c new file mode 100644 index 0000000..9ee1565 --- /dev/null +++ b/helloworld/H5_E1.c @@ -0,0 +1,33 @@ +#include + +int main() { + //1. feladat + printf("%c%c%c\n", 'B', 'y', 'e'); + //2. feladat + int number1 = 123; + float number2 = 123.456; + printf("%d\n%f\n", number1, number2); + printf("%-8d\n%-8f\n", number1, number2); + //3. feladat + int number3 = -15; + int number4 = 150; + int number5 = 1500; + printf( + "-15 hexadecimális formában: %x,\n 150 hexadecimális alakja: %x,\n1500 hexadecimális alakja: %x\n", + number3, + number4, + number5 + ); + //4. feladat + int ch; + setbuf(stdout, NULL); + printf("Please type in one character:\n"); + ch = getchar(); + printf("The character you just entered is:\n"); + putchar (ch); + + return 0; +} + +//5. feladat +// the header stdio.h is missing \ No newline at end of file diff --git a/helloworld/H6_E1.c b/helloworld/H6_E1.c new file mode 100644 index 0000000..c4f8679 --- /dev/null +++ b/helloworld/H6_E1.c @@ -0,0 +1,51 @@ +#include + +int main() { + //1. feladat + //Given x = 1 and y = 3, write a program to print + //out the results of these expressions: x += y, + //x += -y, x -= y, x -= -y, x *= y, and x *= -y. + int x = 1; + int y = 3; + printf("x += y értéke:%d\n", x += y); + x = 1; + printf("x += -y értéke:%d\n", x += (-y)); + x = 1; + printf("x -= y értéke:%d\n", x -= y); + x = 1; + printf("x -= -y értéke:%d\n", x -= (-y)); + x = 1; + printf("x *= y értéke:%d\n", x *= y); + x = 1; + printf("x *= -y értéke:%d\n", x *= (-y)); + + //2. feladat + //Given x = 3 and y = 6, what is the value of z after the expression + //z = x * y == 18 is executed? + // answer is '1' + + //3. feladat + x = 1; + printf("x++ produces: %d\n", x++); + printf("Now x contains: %d\n", x); + + //4. feladat + x = 1; + printf("x = x++ produces: %d\n", x = x++); + printf("Now x contains: %d\n", x); + // x returns 1, bec x=x++ means: x++ returns 1 + + return 0; +} + +/*5. feladat +#include +main() +{ + int x, y; + x = y = 0; + printf("The comparison result is: %d\n", x = y); [x==y is the proper comparison] + return 0; +} +*/ +//setbuf(stdout, NULL); \ No newline at end of file diff --git a/helloworld/H7_E1.c b/helloworld/H7_E1.c new file mode 100644 index 0000000..d26437a --- /dev/null +++ b/helloworld/H7_E1.c @@ -0,0 +1,71 @@ +#include + +int main() { + //1.-2. feladat + //What is the difference between + //the following two pieces of code? + // for (i=0, j=1; i<8; i++, j++) + // printf("%d + %d = %d\n", i, j, i+j); + // + //for (i=0, j=1; i<8; i++, j++); + //printf("%d + %d = %d\n", i, j, i+j); + + //in the line 11 there is an "empty" loop, it does not anyting + + //2. feladat + //Write a program that contains the two pieces of + //code shown in exercise 1, and then execute the program. + //What are you going to see on the screen? + int i; + int j; + printf("2. feladat\n"); + for (i = 0, j = 1; i < 8; i++, j++) + printf("%d + %d = %d\n", i, j, i+j); + + + for (i = 0, j = 1; i < 8; i++, j++); + printf("%d + %d = %d\n", i, j, i+j); + //the 2. loop doesn't do anything + + //3. feladat + //Rewrite the program in Listing 7.4. This time, + //you want the for statement to keep looping until + //the user enters the character K. + int c; + setbuf(stdout, NULL); + printf("\n3. feladat\n"); + printf("Enter a character:\n(enter K to exit)\n"); + c = ' '; + while (c = getc(stdin) != 'K') { + putchar(c); + } + printf("\nOut of the for loop. Bye!\n"); + + + //4. feladat + //Rewrite the program in Listing 7.6 by replacing + //the do-while loop with a for loop. + printf("\n4. feladat\n"); + for (i = 65; i < 72; i++) { + printf("The numeric value of %c is %d.\n", i, i); + } + + //5. feladat + //Rewrite the program in Listing 7.7. + //This time, use a while loop as the outer loop + //and a do-while loop as the inner loop. + i = 1; + printf("\n5. feladat\n"); + while (i <= 3) { // outer loop + printf("The start of iteration %d of the outer loop.\n", i); + j = 1; + do { + printf(" Iteration %d of the inner loop.\n", j); + j++; + } while (j <= 4); + printf("The end of iteration %d of the outer loop.\n", i); + i++; + } + return 0; +} + diff --git a/helloworld/ascii_bitwise.c b/helloworld/ascii_bitwise.c new file mode 100644 index 0000000..c9db2a7 --- /dev/null +++ b/helloworld/ascii_bitwise.c @@ -0,0 +1,7 @@ +#include + +int main(){ + //printf("%c%c%c\n",'B'^0b00100000, 'y'^0b00100000, 'e'^0b00100000); + puts("%c%c%c\n", 'e'); + return 0; +} \ No newline at end of file diff --git a/helloworld/xpp.c b/helloworld/xpp.c new file mode 100644 index 0000000..111d02c --- /dev/null +++ b/helloworld/xpp.c @@ -0,0 +1,27 @@ +#include + +int main() +{ + int x = 1; + printf("x = x + 1 értéke:%d\n",x = x + 1); + printf("Now x contains: %d\n", x); + + x = 1; + printf("x++ produces: %d\n", x++); + printf("Now x contains: %d\n", x); + + + return 0; +} + +/*5. feladat +#include +main() +{ + int x, y; + x = y = 0; + printf("The comparison result is: %d\n", x = y); [x==y is the proper comparison] + return 0; +} +*/ +//setbuf(stdout, NULL); \ No newline at end of file