From 42351efeb96c511aeaf53b0acb5ea8a792fdbf4d Mon Sep 17 00:00:00 2001 From: Goodwitch68 on AcerS7 <56366861+Goodwitch68@users.noreply.github.com> Date: Thu, 31 Oct 2019 13:56:07 +0100 Subject: [PATCH 1/4] H8_E1 done --- helloworld/H8_E1.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 helloworld/H8_E1.c diff --git a/helloworld/H8_E1.c b/helloworld/H8_E1.c new file mode 100644 index 0000000..43dd458 --- /dev/null +++ b/helloworld/H8_E1.c @@ -0,0 +1,51 @@ +//1. Given x = 0xEFFF and y = 0x1000 (that is, EFFF and 1000 as hex values), what +//hex values do you get by evaluating ~x and ~y? +// +// Egymás ellentettjei, ezt már tisztáztuk :-) + +//2. Taking the values of x and y assigned in Exercise 1, write a program that prints +//out the values of !x and !y by using both the %d and %u formats in the printf() +//function. + +#include + +main() { + setbuf(stdout, NULL); + printf("2. feladat. \n"); + int x = 0xEFFF; + int y = 0x1000; + printf("The values of !x and !y is: %d, %d\n", !x, !y); + printf("The values of !x and !y is: %u, %u\n", !x, !y); + + // Na, hogy ennek mi értelme volt :-( + +//3. Given x = 123 and y = 4, write a program that displays the results of the +//expressions x << y and x >> y. + printf("3. feladat. \n"); + x = 123; + y = 4; + printf("The values of x << y is: %d\n", x << y); + printf("The values of x >> y is: %d\n", x >> y); + + + +//4. Write a program that shows the values (in hex) of the expressions 0xFFFF^0x8888, +//0xABCD & 0x4567, and 0xDCBA | 0x1234. + + printf("4. feladat. \n"); + printf("The value of the expressions 0xFFFF^0x8888 is: %X\n", 0xFFFF^0x8888); + printf("The value of the expressions 0xABCD & 0x4567 is: %X\n", 0xABCD & 0x4567); + printf("The value of the expressions 0xDCBA | 0x1234 is: %X\n", 0xDCBA | 0x1234); + +//5. Use the ?: operator and the for statement to write a program that keeps taking the +//characters entered by the user until the character q is accounted. (Hint: Put x!=’q’ +//? 1 : 0 expression as the second expression in a for statement.) + + printf("5. feladat. \n"); + char ch = '0'; + printf("Please type in one character:\n"); + for (int i = 0; ch != 'q' ? 1 : 0;) { + ch = getc( stdin ); + } + return 0; +} \ No newline at end of file From e1f33c69dc009d14767f6a332bef3231779667c5 Mon Sep 17 00:00:00 2001 From: Goodwitch68 on AcerS7 <56366861+Goodwitch68@users.noreply.github.com> Date: Thu, 31 Oct 2019 14:47:22 +0100 Subject: [PATCH 2/4] H9_E1 done --- helloworld/H9_E1.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 helloworld/H9_E1.c diff --git a/helloworld/H9_E1.c b/helloworld/H9_E1.c new file mode 100644 index 0000000..c6a6465 --- /dev/null +++ b/helloworld/H9_E1.c @@ -0,0 +1,60 @@ +//1. Given the following statements, +//int x; +//unsigned int y; +//x = 0xAB78; +//y = 0xAB78; +//write a program to display the decimal values of x and y on the screen. + +#include +#include +main() { + setbuf(stdout, NULL); + printf("1. feladat. \n"); + int x; + unsigned int y; + x = 0xAB78; + y = 0xAB78; + printf("The decimal values of 0xAB78 is: %d\n", x); + printf("The decimal values of 0xAB78 is: %d\n", y); + +//2. Write a program to measure the sizes of short int, long int, and long double +//on your machine. + + printf("2. feladat. \n"); + printf("The size of short int is: %d.\n", sizeof(short int)); + printf("The size of long int is: %d.\n", sizeof(long int)); + printf("The size of long double is: %d.\n", sizeof(long double)); + +//3. Write a program to multiply two signed int variables with positive values, and +//display the result as a long int. + + printf("3. feladat. \n"); + + int a = 12; + int b = 84512; + printf("The productum of the variables is: %ld\n", a * b); + +//4. Write a program to display negative integers in hex format along with their signed int equivalents. + + printf("4. feladat. \n"); + + int neg_num = -1; + printf("Please type in one negative number:\n"); + scanf ("%d", &neg_num); + printf("%x equal %d\n", neg_num, neg_num); + +//5. Given an angle of 30 degrees, write a program to calculate its sine and tangentvalues. + + printf("5. feladat. \n"); + + double angle = 30; + angle *= 3.141593 / 180.0; + printf("The sine of angle 30degree is %f, the tangent of it is: %f\n", sin(angle), tan(angle)); + +//6. Write a program to calculate the non-negative square root of 0x19A1. + printf("6. feladat. \n"); + int hex = 0x19A1; + printf("The square root of 0x19A1 is: %f\n",sqrt(hex)); + + return 0; +} \ No newline at end of file From d51695f0f2a9fd812de1b407646dd6b0eeae7707 Mon Sep 17 00:00:00 2001 From: Goodwitch68 on AcerS7 <56366861+Goodwitch68@users.noreply.github.com> Date: Thu, 31 Oct 2019 15:23:44 +0100 Subject: [PATCH 3/4] =?UTF-8?q?H10=5FE1=20done,=20j=C3=B3l=20sz=C3=B3rakoz?= =?UTF-8?q?tam,=20de=20az=C3=A9rt=20nem=20=C3=A9lveztem=20:-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helloworld/H10_E1.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 helloworld/H10_E1.c diff --git a/helloworld/H10_E1.c b/helloworld/H10_E1.c new file mode 100644 index 0000000..f37fa6a --- /dev/null +++ b/helloworld/H10_E1.c @@ -0,0 +1,67 @@ +//1. Rewrite the program in Listing 10.1. This time, use the logical expression +//i%6 ==0 in the if statement. +#include +main() { + setbuf(stdout, NULL); + printf("1. feladat. \n"); + + int i; + printf("Integers that can be divided by both 2 and 3\n"); + printf("(within the range of 0 to 100):\n"); + for (i=0; i<=100; i++){ + if (i%6 == 0){ + printf(" %d\n", i); + } + } + +//2. Rewrite the program in Listing 10.1 by using nested if statements. + + printf("2. feladat. \n"); + //int i; + printf("Integers that can be divided by both 2 and 3\n"); + printf("(within the range of 0 to 100):\n"); + for (i=0; i<=100; i++){ + if (i%2 == 0) { + if (i % 3 == 0) { + printf(" %d\n", i); + } + } + } + +//3. Write a program to read characters from the standard I/O. If the characters +// are A, B,and C, display their numeric values on the screen. +// (The switch statement is required.) + printf("3. feladat. \n"); + char ch = '0'; + printf("Please type in one character:\n"); + ch = getc( stdin ); + switch (ch) { + case 'A': + printf("A kódja: %d\n", ch); + break; + case 'B': + printf("B kódja: %d\n", ch); + break; + case 'C': + printf("C kódja: %d\n", ch); + break; + default:; + } +//4. Write a program that keeps reading characters from the standard input until +//the character q is entered. + printf("4. feladat. \n"); + printf("Ezt a feladatot a 8. leckénél megoldottuk már :-)\n"); + +//5. Rewrite the program in Listing 10.7. This time, instead of skipping 3 and 5, +//skip the integer that can be evenly divided by both 2 and 3. + printf("5. feladat. \n"); + + int sum = 0; + for (i=1; i<8; i++){ + if ((i % 2 ==0) || (i % 3 ==0)) + continue; + sum += i; + } + printf("The sum of 1, 5, and 7 is: %d\n", sum); + return 0; +} \ No newline at end of file From a058d6005db4b8dd4ec28ac04780490f10bbc7eb Mon Sep 17 00:00:00 2001 From: Goodwitch68 on AcerS7 <56366861+Goodwitch68@users.noreply.github.com> Date: Sat, 9 Nov 2019 07:46:01 +0100 Subject: [PATCH 4/4] Cleanup H8 - 10 --- helloworld/H10_E1.c | 16 +++++++--------- helloworld/H8_E1.c | 4 ++-- helloworld/H9_E1.c | 5 +---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/helloworld/H10_E1.c b/helloworld/H10_E1.c index f37fa6a..f216a1a 100644 --- a/helloworld/H10_E1.c +++ b/helloworld/H10_E1.c @@ -4,12 +4,11 @@ main() { setbuf(stdout, NULL); printf("1. feladat. \n"); - int i; printf("Integers that can be divided by both 2 and 3\n"); printf("(within the range of 0 to 100):\n"); - for (i=0; i<=100; i++){ - if (i%6 == 0){ + for (i=0; i<=100; i++) { + if (i % 6 == 0) { printf(" %d\n", i); } } @@ -17,11 +16,11 @@ main() { //2. Rewrite the program in Listing 10.1 by using nested if statements. printf("2. feladat. \n"); - //int i; + //int i; ha önálló progi lenne, kellene printf("Integers that can be divided by both 2 and 3\n"); printf("(within the range of 0 to 100):\n"); - for (i=0; i<=100; i++){ - if (i%2 == 0) { + for (i=0; i<=100; i++) { + if (i % 2 == 0) { if (i % 3 == 0) { printf(" %d\n", i); } @@ -34,7 +33,7 @@ main() { printf("3. feladat. \n"); char ch = '0'; printf("Please type in one character:\n"); - ch = getc( stdin ); + ch = getc(stdin); switch (ch) { case 'A': printf("A kódja: %d\n", ch); @@ -55,9 +54,8 @@ main() { //5. Rewrite the program in Listing 10.7. This time, instead of skipping 3 and 5, //skip the integer that can be evenly divided by both 2 and 3. printf("5. feladat. \n"); - int sum = 0; - for (i=1; i<8; i++){ + for (i=1; i<8; i++) { if ((i % 2 ==0) || (i % 3 ==0)) continue; sum += i; diff --git a/helloworld/H8_E1.c b/helloworld/H8_E1.c index 43dd458..b1e5ced 100644 --- a/helloworld/H8_E1.c +++ b/helloworld/H8_E1.c @@ -44,8 +44,8 @@ main() { printf("5. feladat. \n"); char ch = '0'; printf("Please type in one character:\n"); - for (int i = 0; ch != 'q' ? 1 : 0;) { - ch = getc( stdin ); + for (int i=0; ch!='q' ? 1 : 0;) { + ch = getc(stdin); } return 0; } \ No newline at end of file diff --git a/helloworld/H9_E1.c b/helloworld/H9_E1.c index c6a6465..a1406e1 100644 --- a/helloworld/H9_E1.c +++ b/helloworld/H9_E1.c @@ -23,7 +23,7 @@ main() { printf("2. feladat. \n"); printf("The size of short int is: %d.\n", sizeof(short int)); printf("The size of long int is: %d.\n", sizeof(long int)); - printf("The size of long double is: %d.\n", sizeof(long double)); + printf("The size of long double is: %d.\n", sizeof(long double)); //3. Write a program to multiply two signed int variables with positive values, and //display the result as a long int. @@ -37,7 +37,6 @@ main() { //4. Write a program to display negative integers in hex format along with their signed int equivalents. printf("4. feladat. \n"); - int neg_num = -1; printf("Please type in one negative number:\n"); scanf ("%d", &neg_num); @@ -46,7 +45,6 @@ main() { //5. Given an angle of 30 degrees, write a program to calculate its sine and tangentvalues. printf("5. feladat. \n"); - double angle = 30; angle *= 3.141593 / 180.0; printf("The sine of angle 30degree is %f, the tangent of it is: %f\n", sin(angle), tan(angle)); @@ -55,6 +53,5 @@ main() { printf("6. feladat. \n"); int hex = 0x19A1; printf("The square root of 0x19A1 is: %f\n",sqrt(hex)); - return 0; } \ No newline at end of file