├── Exercises ├── Chapter_5 │ ├── km_miles │ ├── centi_fahre │ ├── hour_minute │ ├── minute_hour │ ├── sphere_volum │ ├── rectangle_perim │ ├── km_mil.c │ ├── sphere_volume.c │ ├── minute_hour.c │ ├── hour_minute.c │ ├── centi_fahre.c │ └── perimeter_rectangle.c └── Chapter_4 │ ├── hello.c │ ├── isimyaz.c │ ├── eblokbig.c │ ├── hello3big.c │ ├── rectangle.c │ └── hello2.c └── LICENSE /Exercises/Chapter_5/km_miles: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D-K-E/c-practical-reilly/master/Exercises/Chapter_5/km_miles -------------------------------------------------------------------------------- /Exercises/Chapter_4/hello.c: -------------------------------------------------------------------------------- 1 | # include 2 | int main() 3 | { 4 | printf("Hello world!\n"); 5 | return (0); 6 | } 7 | -------------------------------------------------------------------------------- /Exercises/Chapter_5/centi_fahre: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D-K-E/c-practical-reilly/master/Exercises/Chapter_5/centi_fahre -------------------------------------------------------------------------------- /Exercises/Chapter_5/hour_minute: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D-K-E/c-practical-reilly/master/Exercises/Chapter_5/hour_minute -------------------------------------------------------------------------------- /Exercises/Chapter_5/minute_hour: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D-K-E/c-practical-reilly/master/Exercises/Chapter_5/minute_hour -------------------------------------------------------------------------------- /Exercises/Chapter_5/sphere_volum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D-K-E/c-practical-reilly/master/Exercises/Chapter_5/sphere_volum -------------------------------------------------------------------------------- /Exercises/Chapter_5/rectangle_perim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D-K-E/c-practical-reilly/master/Exercises/Chapter_5/rectangle_perim -------------------------------------------------------------------------------- /Exercises/Chapter_4/isimyaz.c: -------------------------------------------------------------------------------- 1 | /* 2 | Program to write my name and social security number etc 3 | 4 | Author: Kaan Eraslan 5 | 6 | Purpose: Exercise 4-1 : Write a program to print your name, social security number, and 7 | date of birth. 8 | 9 | Usage: It shall printout some statements. 10 | 11 | */ 12 | 13 | #include 14 | 15 | int main() 16 | { 17 | printf("Mehmut Mehmude\n"); /* Name */ 18 | printf("123294030\n"); /* social security */ 19 | printf("03/01/1922\n"); /* date of birth */ 20 | /* */ 21 | return(0); 22 | } 23 | -------------------------------------------------------------------------------- /Exercises/Chapter_4/eblokbig.c: -------------------------------------------------------------------------------- 1 | /* 2 | ************* E BLOCK program *************** 3 | 4 | Author: Kaan Eraslan 5 | 6 | Purpose: Write a program to print a block E using asterisks (* ), where the E 7 | has a height of seven characters and a width of five characters. 8 | 9 | Usage: Run the program, it should printout the char. 10 | 11 | */ 12 | #include 13 | 14 | int main() 15 | { 16 | /* ---------- */ 17 | printf("*****\n"); /* The top */ 18 | printf("*\n"); 19 | printf("*\n"); 20 | printf("*****\n"); /* The middle */ 21 | printf("*\n"); 22 | printf("*\n"); 23 | printf("*****\n"); /*The bottom */ 24 | /* ---------- */ 25 | return(0); 26 | } 27 | -------------------------------------------------------------------------------- /Exercises/Chapter_4/hello3big.c: -------------------------------------------------------------------------------- 1 | /* 2 | -------- Big HELLO ------------ 3 | 4 | Author: Kaan Eraslan 5 | Purpose: Write a program to print "HELLO" in big block letters; each letter 6 | should have a height of seven characters and width of five characters. 7 | Usage: Just run the program. 8 | 9 | */ 10 | /* Library Declarations */ 11 | #include 12 | 13 | /* Library Declarations end */ 14 | 15 | /* Variable Declarations */ 16 | 17 | /* Variable Declarations end */ 18 | 19 | int main() 20 | { 21 | printf("* * ***** * * * \n"); 22 | printf("* * * * * * * \n"); 23 | printf("***** ***** * * * * \n"); 24 | printf("* * * * * * * \n"); 25 | printf("* * ***** ***** ***** * \n"); 26 | return(0); 27 | } 28 | -------------------------------------------------------------------------------- /Exercises/Chapter_5/km_mil.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------- Program for Converting Km to Miles ---------- 3 | 4 | Author: Kaan Eraslan 5 | 6 | Purpose: Write a program that converts kilometers per hour to miles per h our. miles = (kilometer · 0.6213712 7 | 8 | Usage: Run the program. Enter number of km, print out the result 9 | */ 10 | 11 | /* Library Declarations */ 12 | 13 | #include 14 | 15 | /* End of Library Declarations */ 16 | 17 | /* Variable Declarations */ 18 | 19 | float km; /* Number of kilometers */ 20 | float miles; /* Number of miles */ 21 | char line[100]; /* Input line from console */ 22 | 23 | /* End of Variable Declarations */ 24 | 25 | int main() 26 | { 27 | printf("Enter km value: "); 28 | fgets(line, sizeof(line), stdin); 29 | sscanf(line, "%f", &km); 30 | /* Operations */ 31 | miles = km * 0.6213712; 32 | /* printout the result */ 33 | printf("Result in miles: %f\n", miles); 34 | return(0); 35 | } 36 | -------------------------------------------------------------------------------- /Exercises/Chapter_4/rectangle.c: -------------------------------------------------------------------------------- 1 | /* 2 | ********* Rectangle Perimeter - Area *************** 3 | 4 | Author: Kaan Eraslan 5 | 6 | Purpose: Write a progra m to compute the area and perimeter of a rectangle 7 | with a width of three inches and a height of five inches. What changes must be made 8 | to the program so that it works for a rectangle with a width of 6.8 inches and a 9 | length of 2.3 inches? 10 | 11 | Usage: Run the program 12 | 13 | */ 14 | #include 15 | /* Variable declarations */ 16 | 17 | int width; /* width of the rectangle, unit: inches */ 18 | int height; /* height of the rectangle, unit: inches */ 19 | int perimeter; /* perimeter of the rectangle, unit: inches */ 20 | int area; /* area of the rectangle, unit: inches */ 21 | 22 | int main() 23 | { 24 | /* operations */ 25 | width = 3; 26 | height = 5; 27 | perimeter = (width * 2) + (height * 2); 28 | area = width * height; 29 | /* Print Result of the Operations */ 30 | printf("Perimeter of the rectangle: %d \n", perimeter); 31 | printf("Area of the rectangle: %d \n", area); 32 | return(0); 33 | } 34 | -------------------------------------------------------------------------------- /Exercises/Chapter_5/sphere_volume.c: -------------------------------------------------------------------------------- 1 | /* 2 | ----------- Programme to Calculate the Volume of the Sphere ---------- 3 | 4 | Author: Kaan Eraslan 5 | 6 | Purpose: Write a program to calculate the volume of a sphere. 7 | 8 | Usage: Run programme. Enter r value and see the result. 9 | 10 | Sphere formula: V = 4/3πr^3 11 | */ 12 | 13 | /* 14 | Library Declarations 15 | */ 16 | #include 17 | 18 | /* 19 | End of Library Declarations 20 | */ 21 | 22 | 23 | /* 24 | Variable Declarations 25 | */ 26 | 27 | float r; /* r value of the sphere */ 28 | float r_power3; /* power 3 of r */ 29 | float result; /* result of the operations */ 30 | const float PI = 3.1415927; /* The classic circle constant */ 31 | char line[100]; /* input line from the console */ 32 | 33 | /* 34 | End of Variable Declarations 35 | */ 36 | int main() 37 | { 38 | printf("Enter r value: "); 39 | fgets(line, sizeof(line), stdin); 40 | sscanf(line, "%f", &r); 41 | /* Operations */ 42 | r_power3 = r * r * r; 43 | result = (4/3) * PI * r_power3; 44 | printf("Result: %f\n", result); 45 | return(0); 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 DKE 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Exercises/Chapter_5/minute_hour.c: -------------------------------------------------------------------------------- 1 | /* 2 | ----- Convert Minutes to Hour - Minutes ------------- 3 | 4 | Author: Kaan Eraslan 5 | Purpose: Write a program that takes hours and minutes as input, and then outputs the total number of minutes. 6 | Usage: Run the program. Enter the hour and minute. Print out the result 7 | */ 8 | 9 | /* Library Declarations */ 10 | 11 | #include 12 | 13 | /* End of Library Declarations */ 14 | 15 | /* Variable Declarations */ 16 | 17 | int hours; /* Number of hours */ 18 | int minutes; /* Number of minutes */ 19 | int remainder_minutes; /* Number of minutes after division */ 20 | char minute_line[50]; /* Input line for minute from console */ 21 | char hour_line[50]; /* Input line for hour from console */ 22 | int result; /* Resulting number from conversion */ 23 | 24 | /* End of Variable Declarations */ 25 | 26 | int main() 27 | { 28 | printf("Enter number in minutes: "); 29 | fgets(minute_line, sizeof(minute_line), stdin); 30 | sscanf(minute_line,"%d", &minutes); 31 | /* Operations */ 32 | remainder_minutes = minutes % 60; 33 | hours = minutes / 60; 34 | printf("%d hours and %d minutes\n", hours, remainder_minutes); 35 | return(0); 36 | } 37 | -------------------------------------------------------------------------------- /Exercises/Chapter_4/hello2.c: -------------------------------------------------------------------------------- 1 | /* ******************************* 2 | 3 | Hello World Program for Demonstration purposes: 4 | 5 | Author: Kaan Eraslan 6 | Taken from: Practical C Programming 7 | Purpose: Demonstration. 8 | 9 | Usage: 10 | 11 | Run the program and the message should appear at the terminal 12 | 13 | 14 | ***********************************/ 15 | #include 16 | /* 17 | the statement #include causes a set of data 18 | declarations to be taken from an include file. 19 | the function printf comes from this package. 20 | 21 | */ 22 | 23 | int main() 24 | { 25 | /* The interior of the 26 | curly brackets is called routine 27 | */ 28 | printf("Hello World!!"); 29 | /* 30 | the function printf is used for displaying output on screen. 31 | the ; indicates the termination of the statement 32 | */ 33 | return (0); 34 | /* return statement (0) 35 | implies that the program exited normally 36 | A nonzero status indicates an e rror—the bigger 37 | the return value, the more severe the error. Typically, 38 | a status of 1 is used for the most simple errors, 39 | like a missing file or bad command -line syntax. 40 | */ 41 | } 42 | -------------------------------------------------------------------------------- /Exercises/Chapter_5/hour_minute.c: -------------------------------------------------------------------------------- 1 | /* 2 | ----- Convert Hour - Minutes to Minutes ------------- 3 | 4 | Author: Kaan Eraslan 5 | Purpose: Write a program that takes hours and minutes as input, and then outputs the total number of minutes. 6 | Usage: Run the program. Enter the hour and minute. Print out the result 7 | */ 8 | 9 | /* Library Declarations */ 10 | 11 | #include 12 | 13 | /* End of Library Declarations */ 14 | 15 | /* Variable Declarations */ 16 | 17 | int hours; /* Number of hours */ 18 | int minutes; /* Number of minutes */ 19 | char minute_line[50]; /* Input line for minute from console */ 20 | char hour_line[50]; /* Input line for hour from console */ 21 | int result; /* Resulting number from conversion */ 22 | 23 | /* End of Variable Declarations */ 24 | int main() 25 | { 26 | /* Hours */ 27 | printf("Enter hours: "); 28 | fgets(hour_line, sizeof(hour_line), stdin); 29 | sscanf(hour_line, "%d", &hours); 30 | /* Minutes */ 31 | printf("Enter minutes: "); 32 | fgets(minute_line, sizeof(minute_line), stdin); 33 | sscanf(minute_line, "%d", &minutes); 34 | /* Operations */ 35 | result = (hours * 60) + minutes; 36 | printf("Result in minutes: %d\n", result); 37 | return(0); 38 | } 39 | -------------------------------------------------------------------------------- /Exercises/Chapter_5/centi_fahre.c: -------------------------------------------------------------------------------- 1 | /* 2 | ------- Program to convert Centigrad to Fahrenheit --------- 3 | 4 | Author: Kaan Eraslan 5 | 6 | Purpose: Write a program t hat converts Centigrade to Fahrenheit 7 | 8 | Usage: Run the program, enter the Centigrade value and obtain the Fahrenheit value. 9 | 10 | */ 11 | 12 | /* Library Declarations */ 13 | 14 | #include 15 | #include 16 | 17 | /* End of Library Declarations */ 18 | 19 | /* Variable Declarations */ 20 | 21 | float celsius; /* celsius number, that is converted number */ 22 | float fahrenheit; /* fahrenheit number, that is resulting number */ 23 | char line[100]; /* input line from the console */ 24 | 25 | /* End of Variable Declarations */ 26 | 27 | int main() 28 | { 29 | /* 30 | Enter User Input 31 | */ 32 | printf("Enter celsius value without degree sign: "); 33 | /* 34 | Read User Input 35 | */ 36 | fgets(line, sizeof(line), stdin); 37 | /* 38 | Scan User Input 39 | */ 40 | sscanf(line, "%f", &celsius); 41 | /* 42 | Operations 43 | */ 44 | fahrenheit = (celsius * 9) / 5 + 32; 45 | /* 46 | Print Output 47 | */ 48 | printf("Result in Fahrenheit: %f\n", fahrenheit); 49 | return(0); 50 | } 51 | -------------------------------------------------------------------------------- /Exercises/Chapter_5/perimeter_rectangle.c: -------------------------------------------------------------------------------- 1 | /* 2 | ------- Program to calculate perimeter of a rectangle ---------- 3 | 4 | Author: Kaan Eraslan 5 | 6 | Purpose: Write a program that prints the perimeter of a rectangle given its height and width. perimeter = 2 · (width + height) 7 | 8 | Usage: Run the program, enter height and width, it prints the result. 9 | */ 10 | 11 | /* Library Declarations */ 12 | 13 | #include 14 | 15 | /* End of Library Declarations */ 16 | 17 | /* Variable Declarations */ 18 | 19 | int width; /* width of the rectangle */ 20 | int height; /* height of the rectangle */ 21 | int perimeter; /* perimeter of the rectangle */ 22 | char width_line[100]; /* input line for width from the console */ 23 | char height_line[100]; /* input line for height from the console */ 24 | 25 | /* End of Variable Declarations */ 26 | 27 | int main() 28 | { 29 | printf("Enter width: "); 30 | fgets(width_line, sizeof(width_line), stdin); 31 | sscanf(width_line, "%d", &width); 32 | /* --------- Height ----------------- */ 33 | printf("Enter height: "); 34 | fgets(height_line, sizeof(height_line), stdin); 35 | sscanf(height_line, "%d", &height); 36 | /* -------- Operations ------------- */ 37 | perimeter = 2 * (width + height); 38 | /* -------- Result --------------- */ 39 | printf("Rectangle Perimeter: %d\n", perimeter); 40 | return(0); 41 | } 42 | --------------------------------------------------------------------------------