diff --git a/helloworld/H10_E1.c b/helloworld/H10_E1.c new file mode 100644 index 0000000..f216a1a --- /dev/null +++ b/helloworld/H10_E1.c @@ -0,0 +1,65 @@ +//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; 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) { + 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 diff --git a/helloworld/H8_E1.c b/helloworld/H8_E1.c new file mode 100644 index 0000000..b1e5ced --- /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 diff --git a/helloworld/H9_E1.c b/helloworld/H9_E1.c new file mode 100644 index 0000000..a1406e1 --- /dev/null +++ b/helloworld/H9_E1.c @@ -0,0 +1,57 @@ +//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