{"id":9872,"date":"2022-06-17T10:47:35","date_gmt":"2022-06-17T10:47:35","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=9872"},"modified":"2023-08-26T16:17:52","modified_gmt":"2023-08-26T10:47:52","slug":"microcontroller-embedded-c-programming-lecture-45-function-exercise","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/","title":{"rendered":"Microcontroller Embedded C Programming Lecture 45| Function exercise"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; line-height: 50px;\"><span style=\"color: #000080;\"><strong>Function exercise<\/strong><\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-size: 25px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #993300;\"><strong>Exercise:<\/strong><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #800080;\"><b>Write a program to do mathematical operations such as addition, subtraction, multiplication, and division of integers.&nbsp;<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You have to follow these two steps.&nbsp;<\/span><\/p>\n<ol class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"font-weight: 400; color: #000000;\"> Do all the mathematical operations in separate functions in a file called math.c<\/span><\/li>\n<li><span style=\"font-weight: 400; color: #000000;\"> Call the functions from the main.c to test them.<\/span><\/li>\n<\/ol>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Basically, your project should contain two source files.<\/span><\/p>\n<figure id=\"attachment_9875\" aria-describedby=\"caption-attachment-9875\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-9875 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-1-1024x500.png\" alt=\"Source files\" width=\"610\" height=\"298\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-1024x500.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-300x146.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-768x375.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-600x293.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-1536x750.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-120x59.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-500x244.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-200x98.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-400x195.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-800x390.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1-1200x586.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1.png 1871w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><figcaption id=\"caption-attachment-9875\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Source files<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">One is math.c, it is written by you. And inside the math.c you have to write functions to do the mathematical operations.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Another source file is main.c. It is written by someone else, and main.c uses functions of math.c.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here you can use the concept of the header file. So, you write all the function definitions in the math.c, and you write all the function prototypes in a file called math.h, and then share that math.h with the main.c.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The implementer of main.c will come to know about the prototype of math.c supported functions by looking at math.h shared by the implementer of math.c.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">I created a project called math. After that, let&#8217;s add two source files. Right-click on project math, click on New, go-to Source file, and I call this as main.c and click on Finish.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And I added another source file that is math.c.<\/span><\/p>\n<figure id=\"attachment_9876\" aria-describedby=\"caption-attachment-9876\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-9876 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-2-1024x343.png\" alt=\"Creating a source file\" width=\"650\" height=\"218\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-1024x343.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-300x100.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-768x257.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-600x201.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-120x40.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-500x167.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-200x67.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-400x134.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2-800x268.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-2.png 1177w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><figcaption id=\"caption-attachment-9876\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Creating a source file<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">So, math.c is excluded from the project. Don&#8217;t worry. For you, it may not be like this. To solve this, go to the properties, go to the C and C++ build, and uncheck the option <\/span><b>Exclude resource from build<\/b><i><span style=\"font-weight: 400;\">.<\/span><\/i><span style=\"font-weight: 400;\"> Then click Apply, Apply and Close, as shown in Figure 3.<\/span><\/span><\/p>\n<figure id=\"attachment_9877\" aria-describedby=\"caption-attachment-9877\" style=\"width: 696px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-9877 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-3-1024x577.png\" alt=\"Properties for math.c\" width=\"696\" height=\"392\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-1024x577.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-300x169.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-768x433.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-600x338.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-120x68.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-500x282.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-200x113.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-400x225.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-800x451.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3-1200x676.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-3.png 1520w\" sizes=\"(max-width: 696px) 100vw, 696px\" \/><figcaption id=\"caption-attachment-9877\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Properties for math.c<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the math.c, we will write all the functions for our arithmetic operations. Before writing functions, let&#8217;s first create the function prototypes.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">So, let&#8217;s create a first function prototype. Name it as <\/span><b>math_add<\/b><span style=\"font-weight: 400;\"> (this is a function name) and after that, give the parenthesis, and inside the parenthesis, write the input arguments. So, this function takes two arguments. It is used to add two numbers of integer type. So, int n1, and int n2.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">It returns a result back to the caller. So, the type of the return value, let&#8217;s consider it as <\/span><b>int<\/b><span style=\"font-weight: 400;\">. Then give the semicolon to terminate the function prototype.&nbsp;&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"padding-left: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b>&nbsp;int math_add(int n1, int n2);<\/b><span style=\"font-weight: 400;\"> \/\/This is a first function prototype.<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">After that, create the function prototypes for other functions. So, let me name it math_sub, math_mul, and math_div.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And for the subtraction also, I would like to use the same math_add prototype.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">After that multiplication. n1 will be multiplied into n2. So, the result may exceed an int range. That&#8217;s why I would like to use the return type <\/span><b>long long int<\/b><span style=\"font-weight: 400;\">.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For the division, here, n1 will be divided by n2, and the result may be float. So, two integer divisions can result in a float. But in &#8216;C,&#8217; integer divisions result in integers, so they will not result in float, but we&#8217;ll see how to convert that into float.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">These are the function prototypes. And let&#8217;s implement all these functions (Figure 4).<\/span><\/p>\n<figure id=\"attachment_9878\" aria-describedby=\"caption-attachment-9878\" style=\"width: 733px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9878\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-4.png\" alt=\"Function\" width=\"733\" height=\"521\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4.png 1003w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4-300x214.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4-768x545.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4-600x426.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4-120x85.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4-500x355.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4-200x142.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4-400x284.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-4-800x568.png 800w\" sizes=\"(max-width: 733px) 100vw, 733px\" \/><figcaption id=\"caption-attachment-9878\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Exercise<\/span><\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s not keep those function prototypes inside math.c. So, for that&nbsp; create one more file called math.h. Let&#8217;s create that header file.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Right-click on the project, select New, and select Header file. After that, Give the header file name as <\/span><b>math.h<\/b><span style=\"font-weight: 400;\">, select the option<\/span><b> Default C header template,<\/b><span style=\"font-weight: 400;\"> and click on <\/span><b>Finish<\/b><span style=\"font-weight: 400;\">.<\/span><\/span><\/p>\n<figure id=\"attachment_9879\" aria-describedby=\"caption-attachment-9879\" style=\"width: 668px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9879\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-5-1024x372.png\" alt=\"Function\" width=\"668\" height=\"243\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-1024x372.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-300x109.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-768x279.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-600x218.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-120x44.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-500x182.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-200x73.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-400x145.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5-800x291.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-5.png 1169w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><figcaption id=\"caption-attachment-9879\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Creating a Header file<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">So, once you create the header file, this IDE automatically adds the macros you can see in Figure 6. These are called as include guards.<\/span><span style=\"font-weight: 400;\"> So, you should make sure that your header file contains this include guards, so if the header file doesn&#8217;t contain this include guards, then you should write this include guards manually.&nbsp;<\/span><\/span><\/p>\n<figure id=\"attachment_9880\" aria-describedby=\"caption-attachment-9880\" style=\"width: 667px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9880\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-6-1024x304.png\" alt=\"Function\" width=\"667\" height=\"198\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-1024x304.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-300x89.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-768x228.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-600x178.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-1536x456.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-120x36.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-500x148.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-200x59.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-400x119.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-800x237.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6-1200x356.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-6.png 1564w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><figcaption id=\"caption-attachment-9880\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. math.h file<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, here #ifndef, #define, #endif is called a pre-processing or pre-processing directive of the &#8216;C&#8217; compiler. And MATH_H can be any value, so it can be a set of any characters. So, it avoids multiple inclusion of the contents of the same header file in a project.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now we are going to keep our function prototypes between these statements.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, we go to math.c and cut the function prototype code from there, and let&#8217;s put that in math.h. So, these are also called exposed function prototypes because the main.c can include this, and it will come to know about the function prototypes of math.c functions.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\"><span style=\"color: #993366;\">#ifndef<\/span> MATH_H_\r\n<span style=\"color: #993366;\">#define<\/span> MATH_H_\r\n\r\n<span style=\"color: #339966;\">\/*these are also called as exposed function prototypes *\/<\/span>\r\n<span style=\"color: #993366;\">int<\/span> math_add(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2);\r\n<span style=\"color: #993366;\">int<\/span> math_sub(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2);\r\n<span style=\"color: #993366;\">long long int<\/span> math_mul(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2);\r\n<span style=\"color: #993366;\">float<\/span> math_div(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2);\r\n\r\n<span style=\"color: #993366;\">#endif<\/span> <span style=\"color: #339966;\">\/* MATH_H_ *\/<\/span><\/pre>\n<p class=\"\">&nbsp;<\/p>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let&#8217;s implement the functions. In math.c, let me just return n1+ n2. So, only one line of code. In math_sub, let me return n1 &#8211; n2.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In math_mul, let&#8217;s return n1 multiplied by n2. To multiply, you have to use the asterisk(*). This results in an integer value. Because n1 is an integer, and n2 is an integer, and if you multiply those two numbers, it will result in an integer.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s move on to the math division. Here, let me want to do n1 divided by n2. And this is also integer division, so here we are dividing two integers. The result will be an integer. It will not be a float value. So, later we will see how to fix this.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #993366;\">int<\/span> math_add(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2)\r\n{\r\n   <span style=\"color: #993366;\">return<\/span> n1+n2;\r\n}\r\n\r\n\r\n<span style=\"color: #993366;\">int<\/span> math_sub(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2)\r\n{\r\n  <span style=\"color: #993366;\"> return<\/span> n1-n2;\r\n}\r\n\r\n\r\n<span style=\"color: #993366;\">long long int<\/span> math_mul(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2)\r\n{\r\n  <span style=\"color: #993366;\"> return<\/span> n1 * n2 ;\r\n}\r\n\r\n\r\n<span style=\"color: #993366;\">float<\/span> math_div(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2)\r\n{\r\n   <span style=\"color: #993366;\">return<\/span> )n1 \/ n2;\r\n}<\/pre>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Our math.c is completed.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Now let&#8217;s go to main.c. In main.c, first, let&#8217;s write the main function. And after that, let&#8217;s give the header file <\/span><b>#include &#8220;math.h&#8221;<\/b><span style=\"font-weight: 400;\"> because we will use those functions implemented in math.c. So, this is how you include a user-defined header file. Functions are written by the user, not given by the standard library. That&#8217;s why I have to include like this. I have to mention the name between the double-quotes. So, all the user-defined header files must be within two double-quotes. And let me include the standard library header file <\/span><b>#include &lt;stdio.h&gt;<\/b><span style=\"font-weight: 400;\">.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">After that, let&#8217;s use those functions. So, let me print those statements. <\/span><b>printf(\u201cAdd,%d\\n\u201d, math_add(0x0FFF1111, 0x0FFF1111));<\/b><span style=\"font-weight: 400;\"> Let me print the result of adding two numbers, so here I use %d.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And here in the printf, I can directly call the math_add function. So, you have to call this function with two numbers. Let me write the first number in hex, 0FFF1111. This is a 4-byte value and positive value because the most significant bit is 0. That&#8217;s why this is a positive value. And after that, let me add another number in hex. So, let me give the same number. So here, <\/span><b>math_add(0x0FFF1111, 0x0FFF1111)<\/b><span style=\"font-weight: 400;\"> is a function call.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Note that you need not to terminate this function call with a semicolon here. It is not required. Because this is a complete &#8216;C&#8217; statement, and a &#8216;C&#8217; statement is terminated by a semicolon. And the math_add returns the result. So, that result will be printed with a format specifier %d.&nbsp;<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #993366;\">#include<\/span> &lt;stdio.h&gt;\r\n<span style=\"color: #993366;\">#include<\/span> \"math.h\"\r\n\r\n<span style=\"color: #993366;\">int<\/span> main(<span style=\"color: #993366;\">void<\/span>)\r\n{\r\n    <span style=\"color: #993366;\">printf<\/span>(\"Add : %d\\n\",math_add(0x0FFF1111 , 0x0FFF1111 ) );\r\n\r\n<span style=\"color: #993366;\">return<\/span> 0;\r\n}<\/pre>\n<figure id=\"attachment_9883\" aria-describedby=\"caption-attachment-9883\" style=\"width: 694px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9883\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-9-1024x597.png\" alt=\"Function\" width=\"694\" height=\"405\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-1024x597.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-300x175.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-768x448.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-600x350.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-1536x895.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-120x70.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-500x291.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-200x117.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-400x233.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-800x466.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9-1200x699.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-9.png 1558w\" sizes=\"(max-width: 694px) 100vw, 694px\" \/><figcaption id=\"caption-attachment-9883\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. main.c file<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s run the program and see the output (Figure 7). You can use a calculator to verify the output.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Suppose you want to print the function in hex format, use format specifier <\/span><b>%X<\/b><span style=\"font-weight: 400;\"> here.<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #993366;\">#include<\/span> &lt;stdio.h&gt;\r\n<span style=\"color: #993366;\">#include<\/span> \"math.h\"\r\n\r\n<span style=\"color: #993366;\">int<\/span> main(<span style=\"color: #993366;\">void<\/span>)\r\n{\r\n<span style=\"color: #993366;\">printf<\/span>(\"Add : %X\\n\",math_add(0x0FFF1111 , 0x0FFF1111 ) );\r\n\r\n<span style=\"color: #993366;\">return<\/span> 0;\r\n}<\/pre>\n<figure id=\"attachment_9884\" aria-describedby=\"caption-attachment-9884\" style=\"width: 679px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9884 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-10-1024x535.png\" alt=\"Print the program in hex format\" width=\"679\" height=\"355\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-1024x535.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-300x157.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-768x402.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-600x314.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-1536x803.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-120x63.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-500x261.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-200x105.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-400x209.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-800x418.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10-1200x627.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-10.png 1551w\" sizes=\"(max-width: 679px) 100vw, 679px\" \/><figcaption id=\"caption-attachment-9884\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Print the program in hex format<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">After that, let&#8217;s call multiplication on the same number. The multiplication of these two numbers will result in a bigger number, and it will be of size 8 bytes. That&#8217;s why I have to use the format specifier <\/span><b>long long int<\/b><span style=\"font-weight: 400;\">. So, that is I64X. And now, let&#8217;s see how it goes.<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\"><span style=\"color: #993366;\">#include<\/span> &lt;stdio.h&gt;\r\n<span style=\"color: #993366;\">#include<\/span> \"math.h\"\r\n\r\n<span style=\"color: #993366;\">int<\/span> main(<span style=\"color: #993366;\">void<\/span>)\r\n{\r\n&nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #993366;\">printf<\/span>(\"Add : %X\\n\", math_add(0x0FFF1111 , 0x0FFF1111 ) );\r\n\r\n&nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #993366;\">printf<\/span>(\"Mul : %I64x\\n\", math_mul(0x0FFF1111 , 0x0FFF1111 ) );\r\n\r\n&nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #993366;\">return<\/span> 0;\r\n}<\/pre>\n<figure id=\"attachment_9885\" aria-describedby=\"caption-attachment-9885\" style=\"width: 553px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9885 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-11-1024x537.png\" alt=\"multiplication\" width=\"553\" height=\"290\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-1024x537.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-300x157.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-768x403.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-600x315.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-120x63.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-500x262.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-200x105.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-400x210.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-800x420.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11-1200x630.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-11.png 1523w\" sizes=\"(max-width: 553px) 100vw, 553px\" \/><figcaption id=\"caption-attachment-9885\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. Multiplication<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s run our code and see the output. This must be the correct answer. And also, let&#8217;s verify it in a calculator. We multiplied by the same number, which resulted in a very big number. The results are shown in Figure 9. Now you can see that the multiplication result is wrong.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, it just printed the last 4 bytes, and the upper 4 bytes are actually discarded. That means there is an information loss.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The reason for that is, if you take a look into the math_mul function in math.c, here we do integer multiplication. Integer multiplied with integer results in an integer. So, now to solve this problem, you have to consider one among these numbers as long long int. That means you have to typecast one of the variables.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">About typecasting, we&#8217;ll see later.&nbsp; But, let&#8217;s use typecasting to solve this issue here.&nbsp; Let&#8217;s change the type of this number to long long int.&nbsp; To casting, in front of the variable name, open the parenthesis and mention the data type name to which you want to cast, as shown Below.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here I am casting to the math_mul variable.&nbsp; I&#8217;m changing the type of this variable to long long int.&nbsp; A long long int variable multiplied with int and results in long long int.&nbsp; So, now it should be good and more on a typecasting we&#8217;ll explore in the later lectures.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">There are two types of casting. One is explicit casting, and another one is implicit casting. And this is explicit casting. That is, you are manually doing that.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">After that, we use typecasting in math_div because an integer divided by integer results in an integer. So, you also have to consider this number as a float. So, you change it to float.&nbsp;<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #993366;\">long long int<\/span> math_mul(<span style=\"color: #993366;\">int<\/span> n1, <span style=\"color: #993366;\">int<\/span> n2)\r\n{\r\n<span style=\"color: #993366;\">    return<\/span> (<span style=\"color: #993366;\">long long int<\/span>)n1 * n2 ;\r\n}\r\n\r\n\r\n<span style=\"color: #993366;\">float<\/span> math_div(<span style=\"color: #993366;\">int<\/span> n1,<span style=\"color: #993366;\"> int<\/span> n2)\r\n{\r\n<span style=\"color: #993366;\">     return<\/span> (<span style=\"color: #993366;\">float<\/span>)n1 \/ n2;\r\n}<\/pre>\n<div class=\"mceTemp\"><\/div>\n<p class=\"\" style=\"text-align: center;\"><span style=\"color: #000000;\">use the typecasting<\/span><\/p>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">In main.c, let&#8217;s write a printf statement to test the division, and the format specifier is <\/span><b>%f<\/b><span style=\"font-weight: 400;\"> for float, and let&#8217;s divide 100 by 8. So, now let&#8217;s run the program, and here you can see that we get the correct answer.&nbsp;<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #993366;\">#include<\/span> &lt;stdio.h&gt;\r\n<span style=\"color: #993366;\">#include<\/span> \"math.h\"\r\n\r\n<span style=\"color: #993366;\">int<\/span> main(<span style=\"color: #993366;\">void<\/span>)\r\n{\r\n&nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #993366;\">printf<\/span>(\"Add : %X\\n\", math_add(0x0FFF1111 , 0x0FFF1111 ) );\r\n\r\n&nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #993366;\">printf<\/span>(\"Mul : %I64x\\n\", math_mul(0x0FFF1111 , 0x0FFF1111 ) );\r\n\r\n&nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #993366;\">printf<\/span>(\"Div : %f\\n\", math_div(100, 8));\r\n\r\n&nbsp; &nbsp; &nbsp; &nbsp;<span style=\"color: #993366;\">return<\/span> 0;\r\n}<\/pre>\n<figure id=\"attachment_9887\" aria-describedby=\"caption-attachment-9887\" style=\"width: 690px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9887\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/06\/Figure-13-1024x533.png\" alt=\"Function \" width=\"690\" height=\"359\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-1024x533.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-300x156.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-768x400.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-600x312.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-1536x799.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-120x62.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-500x260.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-200x104.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-400x208.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-800x416.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13-1200x624.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-13.png 1555w\" sizes=\"(max-width: 690px) 100vw, 690px\" \/><figcaption id=\"caption-attachment-9887\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Output<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now the answer is correct. In the following article, I&#8217;ll be covering<span style=\"color: #ff6600;\"> <a style=\"color: #ff6600;\" href=\"https:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-46-typecasting-in-c\/\" target=\"_blank\" rel=\"noopener\">typecasting<\/a><\/span>.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 20px; line-height: 25px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span><span style=\"color: #0000ff;\">&nbsp;<\/span><\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Function exercise &nbsp; &nbsp; Exercise: Write a program to do mathematical operations such as addition, subtraction, multiplication, and division of integers.&nbsp; You have to follow these two steps.&nbsp; Do all the mathematical operations in separate functions in a file called math.c Call the functions from the main.c to test them. &nbsp; Basically, your project [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9875,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-9872","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Function exercise: Write a program to do mathematical operations<\/title>\n<meta name=\"description\" content=\"Function exercise. Write a C program to perform addition, subtraction, multiplication, and division of integers using separate functions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Function exercise: Write a program to do mathematical operations\" \/>\n<meta property=\"og:description\" content=\"Function exercise. Write a C program to perform addition, subtraction, multiplication, and division of integers using separate functions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-17T10:47:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-26T10:47:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1871\" \/>\n\t<meta property=\"og:image:height\" content=\"913\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming Lecture 45| Function exercise\",\"datePublished\":\"2022-06-17T10:47:35+00:00\",\"dateModified\":\"2023-08-26T10:47:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/\"},\"wordCount\":1804,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Figure-1.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/\",\"name\":\"Function exercise: Write a program to do mathematical operations\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Figure-1.png\",\"datePublished\":\"2022-06-17T10:47:35+00:00\",\"dateModified\":\"2023-08-26T10:47:52+00:00\",\"description\":\"Function exercise. Write a C program to perform addition, subtraction, multiplication, and division of integers using separate functions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Figure-1.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Figure-1.png\",\"width\":1871,\"height\":913,\"caption\":\"Figure 1. Source files\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-45-function-exercise\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming Lecture 45| Function exercise\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Function exercise: Write a program to do mathematical operations","description":"Function exercise. Write a C program to perform addition, subtraction, multiplication, and division of integers using separate functions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/","og_locale":"en_US","og_type":"article","og_title":"Function exercise: Write a program to do mathematical operations","og_description":"Function exercise. Write a C program to perform addition, subtraction, multiplication, and division of integers using separate functions.","og_url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-06-17T10:47:35+00:00","article_modified_time":"2023-08-26T10:47:52+00:00","og_image":[{"width":1871,"height":913,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming Lecture 45| Function exercise","datePublished":"2022-06-17T10:47:35+00:00","dateModified":"2023-08-26T10:47:52+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/"},"wordCount":1804,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/","url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/","name":"Function exercise: Write a program to do mathematical operations","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1.png","datePublished":"2022-06-17T10:47:35+00:00","dateModified":"2023-08-26T10:47:52+00:00","description":"Function exercise. Write a C program to perform addition, subtraction, multiplication, and division of integers using separate functions.","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/06\/Figure-1.png","width":1871,"height":913,"caption":"Figure 1. Source files"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-45-function-exercise\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming Lecture 45| Function exercise"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/9872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=9872"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/9872\/revisions"}],"predecessor-version":[{"id":15626,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/9872\/revisions\/15626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/9875"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=9872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=9872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=9872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}