diff --git a/Joseph Njoroge/Chapter 10/task1.exe b/Joseph Njoroge/Chapter 10/task1.exe index a4e591f..723a92b 100644 Binary files a/Joseph Njoroge/Chapter 10/task1.exe and b/Joseph Njoroge/Chapter 10/task1.exe differ diff --git a/Joseph Njoroge/Chapter 13/task1.exe b/Joseph Njoroge/Chapter 13/task1.exe index 5e78fcd..012d3ca 100644 Binary files a/Joseph Njoroge/Chapter 13/task1.exe and b/Joseph Njoroge/Chapter 13/task1.exe differ diff --git a/Joseph Njoroge/Chapter 13/task2.exe b/Joseph Njoroge/Chapter 13/task2.exe index 30000b4..27499bb 100644 Binary files a/Joseph Njoroge/Chapter 13/task2.exe and b/Joseph Njoroge/Chapter 13/task2.exe differ diff --git a/Joseph Njoroge/Chapter 13/task3.c b/Joseph Njoroge/Chapter 13/task3.c index bb1eb76..6327528 100644 --- a/Joseph Njoroge/Chapter 13/task3.c +++ b/Joseph Njoroge/Chapter 13/task3.c @@ -12,13 +12,13 @@ int main(void) char str[80]; int i, delt = 'A' - 'a'; - printf("Enter a string less than *0 chars log: \n"); + printf("Enter a string less than 80 chars log: \n"); gets( str ); i = 0; while (str[i]) { if ((str[i] >= 'a') && (str[i] <= 'Z')) - str[i] -= delt; //converts to uppercase. + str[i] += delt; //converts to uppercase. ++i; } printf("The entred string is: \n"); diff --git a/Joseph Njoroge/Chapter 13/task3.exe b/Joseph Njoroge/Chapter 13/task3.exe index 7296efd..28913ff 100644 Binary files a/Joseph Njoroge/Chapter 13/task3.exe and b/Joseph Njoroge/Chapter 13/task3.exe differ diff --git a/Joseph Njoroge/Chapter 13/task4.c b/Joseph Njoroge/Chapter 13/task4.c index 95bedbc..31bc0c7 100644 --- a/Joseph Njoroge/Chapter 13/task4.c +++ b/Joseph Njoroge/Chapter 13/task4.c @@ -11,8 +11,7 @@ int main(void) { int x , y; printf("Enter the 2 values: \n"); - scanf("%d %d, &x, &y"); - - printf("The sum of the ints are: %d", x + y); + scanf("%d %d", &x, &y); + printf("The sum of the ints are: %d\n", x + y); return 0; } \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 13/task4.exe b/Joseph Njoroge/Chapter 13/task4.exe index ef0c068..d050ac1 100644 Binary files a/Joseph Njoroge/Chapter 13/task4.exe and b/Joseph Njoroge/Chapter 13/task4.exe differ diff --git a/Joseph Njoroge/Chapter 15/task1.c b/Joseph Njoroge/Chapter 15/task1.c new file mode 100644 index 0000000..87a84b5 --- /dev/null +++ b/Joseph Njoroge/Chapter 15/task1.c @@ -0,0 +1,49 @@ +#include +#include +/** +1. Rewrite the program in Listing 15.2. This time use the format specifier %c, instead +of %s, to print out the character string of the local time on your computer + +include +#include +void GetDateTime(void); +main() +{ +printf(“Before the GetDateTime() function is called.\n”); + GetDateTime(); + printf(“After the GetDateTime() function is called.\n”); + return 0; + } + /* GetDateTime() + void GetDateTime(void) + { + time_t now; + + printf(“Within GetDateTime().\n”); + time(&now); + printf(“Current date and time is: %s\n”, + asctime(localtime(&now))); + } +*/ +void GetDateTime(void); + + +int main(void) +{ + printf("Before the GetDateTime() function is called.\n"); + GetDateTime(); + printf("After the GetDateTime() function is called.\n"); + return 0; + +} + + +void GetDateTime(void) + { + time_t now; + + printf("Within GetDateTime().\n"); + time(&now); + printf("Current date and time is: %s\n", + asctime(localtime(&now))); + } \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 15/task1.exe b/Joseph Njoroge/Chapter 15/task1.exe new file mode 100644 index 0000000..9b12aca Binary files /dev/null and b/Joseph Njoroge/Chapter 15/task1.exe differ diff --git a/Joseph Njoroge/Chapter 15/task2.c b/Joseph Njoroge/Chapter 15/task2.c new file mode 100644 index 0000000..5bf696b --- /dev/null +++ b/Joseph Njoroge/Chapter 15/task2.c @@ -0,0 +1,23 @@ +#include + +/** +2. Declare and define a function, called MultiTwo(), that can perform multiplication +on two integer variables. Call the MultiTwo() function from the main() function +and pass two integers to MultiTwo(). Then print out the result returned by the +MultiTwo() function on the screen. +*/ +int Multitwo(int, int); +int main(void) +{ + int a; + int b; + + a = 9, b = 8; + printf("The multiplication of a and b is: %d\n", Multitwo(a, b)); + return 0; +} + +int Multitwo(int x, int y) +{ + return x * y; +} \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 15/task2.exe b/Joseph Njoroge/Chapter 15/task2.exe new file mode 100644 index 0000000..36d3ecb Binary files /dev/null and b/Joseph Njoroge/Chapter 15/task2.exe differ diff --git a/Joseph Njoroge/Chapter 15/task3.c b/Joseph Njoroge/Chapter 15/task3.c new file mode 100644 index 0000000..237049c --- /dev/null +++ b/Joseph Njoroge/Chapter 15/task3.c @@ -0,0 +1,86 @@ +/** +3. Rewrite the program in Listing 15.3. This time, make a function that takes a variable +number of int arguments and performs the operation of multiplication on +these arguments. + +15L03.c: Processing variable arguments +#include +#include +double MultDouble(int x, ...); +main () +{ +double d1 = 1.5; + double d2 = 2.5; + double d3 = 3.5; + double d4 = 4.5; + + printf(“Given an argument: %2.1f\n”, d1); + printf(“The result returned by MultDouble() is: %2.1f\n\n”, + MultDouble(1, d1)); + printf(“Given arguments: %2.1f and %2.1f\n”, d1, d2); + printf(“The result returned by MultDouble() is: %2.1f\n\n”, + MultDouble(2, d1, d2)); + printf(“Given arguments: %2.1f, %2.1f and %2.1f\n”, d1, d2, d3); + printf(“The result returned by MultDouble() is: %2.1f\n\n”, + MultDouble(3, d1, d2, d3)); + printf(“Given arguments: %2.1f, %2.1f, %2.1f, and %2.1f\n”, + d1, d2, d3, d4); + printf(“The result returned by MultDouble() is: %2.1f\n”, + MultDouble(4, d1, d2, d3, d4)); + return 0; + } + //definition of MultDouble() + double MultDouble(int x, ...) + { + va_list arglist; + int i; + double result = 0.0; + + printf(“The number of arguments is: %d\n”, x); + va_start (arglist, x); + for (i=0; i +#include +double MultDouble(int x, ...); + int main() +{ + double d1 = 6.5; + double d2 = 2.9; + double d3 = 3.5; + double d4 = 4.8; + + printf("Given an argument: %2.1f\n", d1); + printf("The result returned by MultDouble() is: %2.1f\n\n", + MultDouble(1, d1)); + printf("Given arguments: %2.1f and %2.1f\n", d1, d2); + printf("The result returned by MultDouble() is: %2.1f\n\n", + MultDouble(2, d1, d2)); + printf("Given arguments: %2.1f, %2.1f and %2.1f\n", d1, d2, d3); + printf("The result returned by MultDouble() is: %2.1f\n\n", + MultDouble(3, d1, d2, d3)); + printf("Given arguments: %2.1f, %2.1f, %2.1f, and %2.1f\n", + d1, d2, d3, d4); + printf("The result returned by MultDouble() is: %2.1f\n", + MultDouble(4, d1, d2, d3, d4)); + return 0; + } + //definition of MultDouble() + double MultDouble(int x, ...) + { + va_list arglist; + int i; + double result = 0.0; + + printf("The number of arguments is: %f\n", x); + va_start (arglist, x); + for (i=0; i +#include + +double AddDouble(int x, ...); + +int main() +{ +double d1 = 1.5; +double d2 = 2.5; +double d3 = 3.5; +double d4 = 4.5; +printf("Given an argument: %2.1f\n", d1); +printf("The result returned by AddDouble() is: %2.1f\n\n", +AddDouble(1, d1)); +printf("Given arguments: %2.1f and %2.1f\n", d1, d2); +printf("The result returned by AddDouble() is: %2.1f\n\n", +AddDouble(2, d1, d2)); +printf("Given arguments: %2.1f, %2.1f and %2.1f\n", d1, d2, d3); +printf("The result returned by AddDouble() is: %2.1f\n\n", +AddDouble(3, d1, d2, d3)); +printf("Given arguments: %2.1f, %2.1f, %2.1f, and %2.1f\n", +d1, d2, d3, d4); +printf("The result returned by AddDouble() is: %2.1f\n", +AddDouble(4, d1, d2, d3, d4)); +return 0; +} +/* definition of AddDouble() */ +double AddDouble(int x, ...) +{ +va_list arglist; +int i; +double result = 0.0; +printf("The number of arguments is: %d\n", x); +va_start (arglist, x); +for (i=0; i + +int main() +{ + char str[] = "My name is Joseph"; + int list[] = {1, 2, 3, 4, 5}; + char *str_ptr = str; + int *int_ptr = list; + + printf("Before the change: %s\n", str); + *(str_ptr + 3) = 'N'; + printf("After the change: %s\n", str); + + printf("Before the list: %d\n", list[1]); + *(int_ptr + 1) = 78888; + printf("Before the list: %d\n", list[1] ); + + return 0; +} \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 16/task1.exe b/Joseph Njoroge/Chapter 16/task1.exe new file mode 100644 index 0000000..57be4a0 Binary files /dev/null and b/Joseph Njoroge/Chapter 16/task1.exe differ diff --git a/Joseph Njoroge/Chapter 16/task2.c b/Joseph Njoroge/Chapter 16/task2.c new file mode 100644 index 0000000..c661599 --- /dev/null +++ b/Joseph Njoroge/Chapter 16/task2.c @@ -0,0 +1,20 @@ +#include + +/** +Given a character string, I like C!, write a program to pass the string to a function +that displays the string on the screen. +*/ +void stringingify(char *ptr); + +int main() +{ + char str[] = "I like C!"; + char *str_ptr; + str_ptr = str; + stringingify(str_ptr); +} + +void stringingify(char *ptr) +{ + printf("%s", ptr); +} \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 16/task2.exe b/Joseph Njoroge/Chapter 16/task2.exe new file mode 100644 index 0000000..108702f Binary files /dev/null and b/Joseph Njoroge/Chapter 16/task2.exe differ diff --git a/Joseph Njoroge/Chapter 16/task3.c b/Joseph Njoroge/Chapter 16/task3.c new file mode 100644 index 0000000..7410873 --- /dev/null +++ b/Joseph Njoroge/Chapter 16/task3.c @@ -0,0 +1,24 @@ +#include + +/** +Rewrite the program in exercise 1. This time, change the string of I like C! to I +love C! by moving a pointer that is initialized with the start address of the string +and updating the string with new characters. Then, pass the updated string to the +function to display the content of the string on the screen. +*/ + +void stringy(char *ptr); +int main() +{ + char str[] = "I love C!"; + char str2[] = "I like C!"; + char *char_ptr; + char_ptr = str; + stringy(char_ptr); + return 0; +} + +void stringy(char *ptr) +{ + printf("%s", ptr); +} \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 16/task3.exe b/Joseph Njoroge/Chapter 16/task3.exe new file mode 100644 index 0000000..14a504a Binary files /dev/null and b/Joseph Njoroge/Chapter 16/task3.exe differ diff --git a/Joseph Njoroge/Chapter 16/task4.c b/Joseph Njoroge/Chapter 16/task4.c new file mode 100644 index 0000000..f41fbe7 --- /dev/null +++ b/Joseph Njoroge/Chapter 16/task4.c @@ -0,0 +1,13 @@ +#include + +/** +Given a two-dimensional character array, str, that is initialized as +char str[2][15] = { “You know what,”, “C is powerful.” }; +write a program to pass the start address of str to a function that prints out the +content of the character array. +*/ + +int main() +{ + +} \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 8/task5.c b/Joseph Njoroge/Chapter 8/task5.c index 7c05849..f9a6933 100644 --- a/Joseph Njoroge/Chapter 8/task5.c +++ b/Joseph Njoroge/Chapter 8/task5.c @@ -8,9 +8,16 @@ characters entered by the user until the character q is accounted. (Hint: Put x! int main(void) { - char c = ' '; - c = getchar(); - c != 'q' ? 1 : 0; + char c; + printf("Enter a character: "); + + for (c = ' '; c != 'A' && c != 'a';) + { + c = getc(stdin); + //printf("%c", c); + putchar(c); + } + printf("\nOut of the loop\n"); return 0; } \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 8/task5.exe b/Joseph Njoroge/Chapter 8/task5.exe index 1550a16..35dd5ef 100644 Binary files a/Joseph Njoroge/Chapter 8/task5.exe and b/Joseph Njoroge/Chapter 8/task5.exe differ diff --git a/Joseph Njoroge/Chapter 8/tempCodeRunnerFile.c b/Joseph Njoroge/Chapter 8/tempCodeRunnerFile.c new file mode 100644 index 0000000..3d4c6b7 --- /dev/null +++ b/Joseph Njoroge/Chapter 8/tempCodeRunnerFile.c @@ -0,0 +1 @@ + 0; \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 9/task1.c b/Joseph Njoroge/Chapter 9/task1.c index 759b041..cff5b2f 100644 --- a/Joseph Njoroge/Chapter 9/task1.c +++ b/Joseph Njoroge/Chapter 9/task1.c @@ -17,6 +17,6 @@ int main(void) x = 0xAB78; y = 0xAB78; - printf("The decimal value of x and y are %d and %u respectively.\n", x, y); + printf("The decimal value of x and y are %d and %d\n respectively.\n", x, y); return 0; } \ No newline at end of file diff --git a/Joseph Njoroge/Chapter 9/task1.exe b/Joseph Njoroge/Chapter 9/task1.exe index 95e2f1b..d6d5e50 100644 Binary files a/Joseph Njoroge/Chapter 9/task1.exe and b/Joseph Njoroge/Chapter 9/task1.exe differ diff --git a/test1.c b/test1.c new file mode 100644 index 0000000..c31185c --- /dev/null +++ b/test1.c @@ -0,0 +1,12 @@ +#include + + +int main() +{ +int num; +printf("Enter a single digit that can be divided\nby both 2 and 3:\n"); +for (num = 1; (num%2 != 0) || (num%3 != 0);) + num = getchar() - '0'; + printf("You got such a number: %d\n", num); + return 0; +} \ No newline at end of file diff --git a/test1.exe b/test1.exe new file mode 100644 index 0000000..effeeb1 Binary files /dev/null and b/test1.exe differ