<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7304028535821151454</id><updated>2012-01-14T11:01:44.106+08:00</updated><category term='if statement'/><category term='Introduction'/><category term='Two-dimensional array'/><category term='switch Statement'/><category term='Logical Operator'/><category term='Computer-aided Learning Multiplication Problem&apos;s Source Code'/><category term='Defining a Function'/><category term='Infinite Loop'/><category term='Call-by-value'/><category term='while Loop'/><category term='double'/><category term='do while Loop'/><category term='char'/><category term='Computer-aided Learning Multiplication Problem'/><category term='Arrays'/><category term='Arithmetic Operator'/><category term='Global Variable'/><category term='for Loop'/><category term='Character Array'/><category term='Declare arrays'/><category term='Introduction to Functions'/><category term='Associativity'/><category term='break'/><category term='Relational Operator'/><category term='Selection Structure'/><category term='printf'/><category term='int'/><category term='if else statement'/><category term='Data Type'/><category term='Variable'/><category term='Increment and Decrement Operator'/><category term='#define'/><category term='Function Execution Sequence'/><category term='Variable Scope'/><category term='Repetition Structure'/><category term='Initialize arrays'/><category term='Nested if'/><category term='I/O'/><category term='scanf'/><category term='Nested Loop'/><category term='I/O Character Arrays'/><category term='Precedence'/><category term='C/C++ IDE'/><category term='Electricity Bill Problem Source Code'/><category term='float'/><category term='Null Character'/><category term='Electricity Bill Problem'/><title type='text'>beginning C programming</title><subtitle type='html'>easy to understand C tutorials with examples and problems for absolute beginners.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-8486387764597261466</id><published>2009-06-01T10:28:00.016+08:00</published><updated>2009-06-06T17:43:44.471+08:00</updated><title type='text'>Tutorial 8.4: Passing Arrays to Functions</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;/span&gt;An array can be passed as an argument to a function. Remember the mechanism of call-by-value. When we pass variables to a function, copy of their values are made for the function. Therefore any changes to the copy do not affect the original variables' value. But in the case of passing an array to a function, we are actually passing the memory location of the array which is its address. It is because the name of arrays evaluates to the address of the first element of the array. Thus, the called function can modifies the actual values in the original array since it knows exactly where the array is stored in the memory. The following program demonstrates that an array name is actually the address of its first element.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/SiNxjn4dH6I/AAAAAAAAAWI/1hk_kh4DrbA/s1600-h/Session8-arrayaddress.png"&gt;&lt;img style="cursor: pointer; width: 275px; height: 161px;" src="http://1.bp.blogspot.com/_264sc_gncA4/SiNxjn4dH6I/AAAAAAAAAWI/1hk_kh4DrbA/s400/Session8-arrayaddress.png" alt="" id="BLOGGER_PHOTO_ID_5342238439806672802" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&amp;amp;a[0] = 0022FF20&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;amp;a = 0022FF20&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a = 0022FF20&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Printing the address of the array's first element and its name yields the same output. The %p is a conversion specifier for printing address. As usual we will look at an example on how to pass an array to a function. It also demonstrates that a function can modify the elements in an array.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/SiSBL5HljHI/AAAAAAAAAWQ/1PPV4W3Ra6E/s1600-h/Session8-passarray-main.png"&gt;&lt;img style="cursor: pointer; width: 387px; height: 304px;" src="http://3.bp.blogspot.com/_264sc_gncA4/SiSBL5HljHI/AAAAAAAAAWQ/1PPV4W3Ra6E/s400/Session8-passarray-main.png" alt="" id="BLOGGER_PHOTO_ID_5342537099279436914" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/SiSIndJPrBI/AAAAAAAAAW4/RAjr2YYa9no/s1600-h/Session8-passarray-func.png"&gt;&lt;img style="cursor: pointer; width: 379px; height: 79px;" src="http://3.bp.blogspot.com/_264sc_gncA4/SiSIndJPrBI/AAAAAAAAAW4/RAjr2YYa9no/s400/Session8-passarray-func.png" alt="" id="BLOGGER_PHOTO_ID_5342545269387930642" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;br /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;25&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First, an integer array &lt;span style="font-family:courier new;"&gt;a&lt;/span&gt; which contains five elements is declared.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/SiSCCkyU56I/AAAAAAAAAWg/91gCysyKW0M/s1600-h/Session8-passarray-main-displayarray.png"&gt;&lt;img style="cursor: pointer; width: 387px; height: 32px;" src="http://1.bp.blogspot.com/_264sc_gncA4/SiSCCkyU56I/AAAAAAAAAWg/91gCysyKW0M/s400/Session8-passarray-main-displayarray.png" alt="" id="BLOGGER_PHOTO_ID_5342538038714361762" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Then we use for repetition statement to display the elements of the array. &lt;span style="font-family:courier new;"&gt;\t&lt;/span&gt; is an escape sequence that is used to insert horizontal tab. Once all the elements are displayed, a newline escape sequence is outputted to position the cursor at the beginning of the next line.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/SiSEpLdkrMI/AAAAAAAAAWo/ZuLGbZsOVmY/s1600-h/Session8-passarray-main-callfunc.png"&gt;&lt;img style="cursor: pointer; width: 387px; height: 17px;" src="http://3.bp.blogspot.com/_264sc_gncA4/SiSEpLdkrMI/AAAAAAAAAWo/ZuLGbZsOVmY/s400/Session8-passarray-main-callfunc.png" alt="" id="BLOGGER_PHOTO_ID_5342540900954582210" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next function &lt;span style="font-family:courier new;"&gt;SquareArray&lt;/span&gt; is invoked. The array &lt;span style="font-family:courier new;"&gt;a&lt;/span&gt; and its size are passed as the arguments to the called function.&lt;br /&gt;&lt;br /&gt;Finally we re-display the elements of the array to see changes made by function &lt;span style="font-family:courier new;"&gt;SquareArray&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;The following is the function definition of &lt;span style="font-family:courier new;"&gt;SquareArray&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/SiSIndJPrBI/AAAAAAAAAW4/RAjr2YYa9no/s1600-h/Session8-passarray-func.png"&gt;&lt;img style="cursor: pointer; width: 379px; height: 79px;" src="http://3.bp.blogspot.com/_264sc_gncA4/SiSIndJPrBI/AAAAAAAAAW4/RAjr2YYa9no/s400/Session8-passarray-func.png" alt="" id="BLOGGER_PHOTO_ID_5342545269387930642" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The function expects two arguments, an integer array and integer variable. It does not returns any value to the caller.The definition consists of integer variable &lt;span style="font-family:courier new;"&gt;i&lt;/span&gt; declaration and &lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; repetition statement.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/SiSL9suCdxI/AAAAAAAAAXA/yWiMrtNshek/s1600-h/Session8-passarray-func-forstatment.png"&gt;&lt;img style="cursor: pointer; width: 379px; height: 17px;" src="http://3.bp.blogspot.com/_264sc_gncA4/SiSL9suCdxI/AAAAAAAAAXA/yWiMrtNshek/s400/Session8-passarray-func-forstatment.png" alt="" id="BLOGGER_PHOTO_ID_5342548950060791570" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; statement repeats for the number of elements (size of the array) and performs square operation on each element of the array.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-8486387764597261466?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/8486387764597261466/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/06/tutorial-84-passing-arrays-to-functions.html#comment-form' title='41 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/8486387764597261466'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/8486387764597261466'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/06/tutorial-84-passing-arrays-to-functions.html' title='Tutorial 8.4: Passing Arrays to Functions'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_264sc_gncA4/SiNxjn4dH6I/AAAAAAAAAWI/1hk_kh4DrbA/s72-c/Session8-arrayaddress.png' height='72' width='72'/><thr:total>41</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-1500217434834578423</id><published>2009-05-30T14:50:00.011+08:00</published><updated>2009-06-10T16:28:44.096+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Two-dimensional array'/><title type='text'>Tutorial 8.3: Two-dimensional Arrays</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(173, 215, 107);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Up until now, we have been dealing with arrays with one index value as reference to its elements. These arrays are called one-dimensional arrays. In C we can declare arrays of two dimensions. Two-dimension arrays is illustrated in the following figure.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/SiEOApq5oaI/AAAAAAAAAVE/DG_mb6OI7r0/s1600-h/Session8-two-dim+array.png"&gt;&lt;img style="cursor: pointer; width: 227px; height: 172px;" src="http://3.bp.blogspot.com/_264sc_gncA4/SiEOApq5oaI/AAAAAAAAAVE/DG_mb6OI7r0/s400/Session8-two-dim+array.png" alt="" id="BLOGGER_PHOTO_ID_5341566037386699170" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The array contains three rows and four columns (3-by-4 array). Two-dimensional arrays are commonly used to represent table of values that are arranged in rows and columns. For example, we could use a two-dimensional array to store information of student's course works for C programming course. What if we have several courses? We could use a three-dimensional array to store the information. One dimension would be for student's ids, one dimension for the scores and the third for the courses.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(173, 215, 107);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Defining and Initializing Two-dimensional Arrays&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Now lets look at how we can declare a two-dimensional array. A two-dimensional array is declared as&lt;br /&gt;&lt;br /&gt;int coursework[20][5];&lt;br /&gt;&lt;br /&gt;The statement declares an array coursework containing twenty rows and five columns. As one-dimensional array, the index value of two-dimensional arrays with 0. Therefore, the reference for the first row and columns is coursework[0][0].&lt;br /&gt;&lt;br /&gt;The basic structure of initializing a two-dimensional array much like a one-dimensional array. For example&lt;br /&gt;&lt;br /&gt;int a[3][4] = { {2, 4, 6, 8}, {1, 3, 5, 7}, {2, 5, 3, 6} };&lt;br /&gt;&lt;br /&gt;The values for each row are grouped  in braces. The first group of values in the braces initializes the row 0. The next group initializes row 1 and the last group is for row 2. If we specify not enough initializing values for a given elements in a row, that elements will be initialized to zero.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(173, 215, 107); font-weight: bold;"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/06/tutorial-84-passing-arrays-to-functions.html"&gt;Passing Arrays to Functions&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-1500217434834578423?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/1500217434834578423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-83-two-dimensional-arrays.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1500217434834578423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1500217434834578423'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-83-two-dimensional-arrays.html' title='Tutorial 8.3: Two-dimensional Arrays'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_264sc_gncA4/SiEOApq5oaI/AAAAAAAAAVE/DG_mb6OI7r0/s72-c/Session8-two-dim+array.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-2166350442720858292</id><published>2009-05-26T00:19:00.004+08:00</published><updated>2009-06-10T16:30:08.618+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Character Array'/><category scheme='http://www.blogger.com/atom/ns#' term='Null Character'/><category scheme='http://www.blogger.com/atom/ns#' term='I/O Character Arrays'/><title type='text'>Tutorial 8.2: Using Character Arrays</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Defining and Initializing Character Arrays&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;We have discussed integer arrays in the previous tutorials. Now we will be looking at how character arrays can be used to store strings. For example, we initialize a &lt;span style="font-family:courier new;"&gt;char&lt;/span&gt; array string which has 20 elements as follows&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;char string1[20];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Although array &lt;span style="font-family:courier new;"&gt;string1&lt;/span&gt; is defined to have 20 elements, actually it can hold up to 19 characters only. In C, a special string-termination character '&lt;span style="font-family:courier new;"&gt;\0&lt;/span&gt;' called &lt;span style="color: rgb(51, 102, 255);"&gt;null character&lt;/span&gt; is added at the end of a string. The null-character is there to indicate where a string end. Therefore when declaring a &lt;span style="font-family:courier new;"&gt;char&lt;/span&gt; array, we should always remember to define it large enough to hold the number of characters and the null character. The following figure illustrates a char array &lt;span style="font-family:courier new;"&gt;s&lt;/span&gt; holding a string "hello". The null character is added as the last character in the string.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Shn8PT8-_OI/AAAAAAAAARc/mPN9_v1quKU/s1600-h/Session8-stringinarray.png"&gt;&lt;img style="cursor: pointer; width: 247px; height: 75px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Shn8PT8-_OI/AAAAAAAAARc/mPN9_v1quKU/s400/Session8-stringinarray.png" alt="" id="BLOGGER_PHOTO_ID_5339576173208730850" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now lets look at how to initialize a &lt;span style="font-family:courier new;"&gt;char&lt;/span&gt; array. For example&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;char string2[] = "Good Morning";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Each element of the array is initialized to contain one character of the string. Note that we haven't specified the size of the array. We let the compiler assigns the size of the array based on the length of the string. &lt;span style="font-family:courier new;"&gt;&lt;/span&gt;Character arrays also can be initialize as follows.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;char string3[20] = "The end";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The first seven elements will contain the specified string and the null character will be added to the seventh element. The rest still can be used because the memory locations are already allocated for &lt;span style="font-family:courier new;"&gt;string3&lt;/span&gt;.&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;I/O Character Arrays&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;A string can be inputted into a character array using &lt;span style="font-family:courier new;"&gt;scanf&lt;/span&gt; with conversion specifier &lt;span style="font-family:courier new;"&gt;%s&lt;/span&gt;. For example,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;char string1[10];&lt;/span&gt; &lt;span style="font-family:courier new;"&gt;scanf("%s", string1);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note that the normally used &lt;span style="font-family:courier new;"&gt;&amp;amp;&lt;/span&gt; is omitted in the statement. This is because the name of the array is already an address which is corresponding to the address of the first element of the array. Function &lt;span style="font-family:courier new;"&gt;scanf&lt;/span&gt; will read characters until a space, tab or newline is encountered. Another important matter that we have to consider is the length of the string inputted. It should be no longer than 9 characters because the last element is reserved for the null character. Therefore it is better to use the conversion specifier &lt;span style="font-family:courier new;"&gt;9%s&lt;/span&gt; to make sure only 9 characters will be read during the process of input.&lt;br /&gt;&lt;br /&gt;A character array is printed using &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt; with conversion specifier &lt;span style="font-family:courier new;"&gt;%s&lt;/span&gt;. For example,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;printf("The string is %s.\n", string1);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Function &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt; will print the characters in the array until null character is encountered.&lt;br /&gt;&lt;br /&gt;An example of using character array.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/ShrAuiMsANI/AAAAAAAAARs/h05ZPMViGAI/s1600-h/Session8-chararray.png"&gt;&lt;img style="cursor: pointer; width: 327px; height: 240px;" src="http://3.bp.blogspot.com/_264sc_gncA4/ShrAuiMsANI/AAAAAAAAARs/h05ZPMViGAI/s400/Session8-chararray.png" alt="" id="BLOGGER_PHOTO_ID_5339792213887680722" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Enter your name: Haris&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Good Morning! Haris&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Haris&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/ShrBBvuYSgI/AAAAAAAAAR0/cyb3M2Y4fBc/s1600-h/Session8-chararray+-+1.png"&gt;&lt;img style="cursor: pointer; width: 327px; height: 43px;" src="http://3.bp.blogspot.com/_264sc_gncA4/ShrBBvuYSgI/AAAAAAAAAR0/cyb3M2Y4fBc/s400/Session8-chararray+-+1.png" alt="" id="BLOGGER_PHOTO_ID_5339792543936170498" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here we have declared integer variable &lt;span style="font-family:courier new;"&gt;i&lt;/span&gt; and two character arrays namely &lt;span style="font-family:courier new;"&gt;string1&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;string2&lt;/span&gt;. &lt;span style="font-family:courier new;"&gt;string1&lt;/span&gt;'s size is set to 20 while &lt;span style="font-family:courier new;"&gt;string2&lt;/span&gt; is initialized to hold a string "Good Morning!".&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/ShrCkpqoRKI/AAAAAAAAAR8/ype487OOKRw/s1600-h/Session8-chararray+-+2.png"&gt;&lt;img style="cursor: pointer; width: 327px; height: 43px;" src="http://3.bp.blogspot.com/_264sc_gncA4/ShrCkpqoRKI/AAAAAAAAAR8/ype487OOKRw/s400/Session8-chararray+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5339794243116876962" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A prompt message is printed to ask the user to enter his/her name. The entered name is stored in array &lt;span style="font-family:courier new;"&gt;string1&lt;/span&gt;. Then both arrays' contents are printed using function &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/ShrCmeo-QUI/AAAAAAAAASE/9PgEAwnkaNk/s1600-h/Session8-chararray+-+3.png"&gt;&lt;img style="cursor: pointer; width: 327px; height: 43px;" src="http://4.bp.blogspot.com/_264sc_gncA4/ShrCmeo-QUI/AAAAAAAAASE/9PgEAwnkaNk/s400/Session8-chararray+-+3.png" alt="" id="BLOGGER_PHOTO_ID_5339794274516877634" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; repetition statement prints the content of &lt;span style="font-family:courier new;"&gt;string1&lt;/span&gt; element-by-element until the null character is encountered. This is achieved by specifying the loop condition to &lt;span style="font-family:courier new;"&gt;string1[i] != '\0'&lt;/span&gt;. Note that conversion specifier &lt;span style="font-family:courier new;"&gt;%c&lt;/span&gt; is used since we are printing a character in each iteration.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-83-two-dimensional-arrays.html"&gt;Two-dimensional Arrays&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-2166350442720858292?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/2166350442720858292/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-82-using-character-arrays_26.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/2166350442720858292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/2166350442720858292'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-82-using-character-arrays_26.html' title='Tutorial 8.2: Using Character Arrays'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_264sc_gncA4/Shn8PT8-_OI/AAAAAAAAARc/mPN9_v1quKU/s72-c/Session8-stringinarray.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-961722441867790559</id><published>2009-05-22T09:18:00.003+08:00</published><updated>2009-06-10T16:31:16.555+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Initialize arrays'/><category scheme='http://www.blogger.com/atom/ns#' term='Declare arrays'/><category scheme='http://www.blogger.com/atom/ns#' term='Arrays'/><title type='text'>Tutorial 8.1: Arrays</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Lets revise &lt;a href="http://begincprogram.blogspot.com/2009/05/session-2-variables-and-data-types.html"&gt;what is a variable&lt;/a&gt;? A variable is a memory location that can store a value. An array is sequence of memory locations that have the same name and type. Thus we can say that an array is a collection of the same type of variables.&lt;br /&gt;&lt;br /&gt;The following illustrates the graphical representation of an array.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/ShYC89ZvTvI/AAAAAAAAAQg/1qye-HEjWcE/s1600-h/Session8-arrayrepresentation.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 140px;" src="http://3.bp.blogspot.com/_264sc_gncA4/ShYC89ZvTvI/AAAAAAAAAQg/1qye-HEjWcE/s400/Session8-arrayrepresentation.png" alt="" id="BLOGGER_PHOTO_ID_5338457654592229106" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The array name is a and it has 10 elements. The name of an array can be declared like other variable names. It can contain letters, digit, underscore and cannot begins with digit. All the array's elements have the same data type, int, char or any legal type in C. Each element has its index number and we refer to an element using their index number. Thus if we want to access the fifth element for example, we refer it as a[4]. Notice that the first element of arrays start with zero.&lt;br /&gt;&lt;br /&gt;So what is the usefulness of arrays? Arrays are used when we want to store information that have relation such as student's scores, item's prices etc. Of course we can use variables to store the student's scores such as follows.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int s1,s2,s3,s4,s5,s6,s7,s8,s9,s10;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;printf("Enter 7 scores: \n");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;scanf("%d%d%d%d%d%d%d%d%d%d",&amp;amp;s1,&amp;amp;s2,&amp;amp;s3,&amp;amp;s4,&amp;amp;s5,&amp;amp;s6,&amp;amp;s7,&amp;amp;s8,&amp;amp;s9,&amp;amp;s10);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This would work but what if we need to store 100 scores or 1000 scores. Its almost impossible to program such task. Well, this is where an array can be useful.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Defining and Initializing Arrays&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Lets look at how to declare an array. Its like how we declare a variable except that we need to specify its size in square bracket.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int a[10];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here we declare an integer array a that has 10 elements. We may define arrays to contain other data types such as char, float and double.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;char a[10];&lt;/span&gt; &lt;span style="font-family:courier new;"&gt;float a[10];&lt;/span&gt; &lt;span style="font-family:courier new;"&gt;double a[10];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now we know how to declare an array, lets looks at how to initialize it. The simplest way to initialize an array is as follows.&lt;br /&gt;&lt;br /&gt;int a[10] = {32, 78, 64, 90, 27, 82, 18, 60, 94, 58};&lt;br /&gt;&lt;br /&gt;Here we assign 32 to the the 1st element, 78 to the second element and so on. If there are fewer specified values than elements, the remaining elements are initialized to zero. For example,&lt;br /&gt;&lt;br /&gt;int a[10] = {32, 78, 64, 90};&lt;br /&gt;&lt;br /&gt;All elements of an array could have been initialized to zero as follows.&lt;br /&gt;&lt;br /&gt;int a[10] = {0};&lt;br /&gt;&lt;br /&gt;Now we know how to declare and initialize an array, lets look at an example. The program utilizes for statement structure to store 10 student's scores into an array.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/ShYcau7vcJI/AAAAAAAAAQo/ajezcWopZ6E/s1600-h/Session8-arrayinitialise.png"&gt;&lt;img style="cursor: pointer; width: 371px; height: 257px;" src="http://2.bp.blogspot.com/_264sc_gncA4/ShYcau7vcJI/AAAAAAAAAQo/ajezcWopZ6E/s400/Session8-arrayinitialise.png" alt="" id="BLOGGER_PHOTO_ID_5338485653895082130" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Enter student's scores:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;15&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;48&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;68&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;92&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;37&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;82&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;64&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;79&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;57&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;62&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Your student's scores are:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;15&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;48&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;68&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;92&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;37&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;82&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;64&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;79&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;57&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;62&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-82-using-character-arrays_26.html"&gt;Character Arrays&lt;/a&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-961722441867790559?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/961722441867790559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-81-arrays.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/961722441867790559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/961722441867790559'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-81-arrays.html' title='Tutorial 8.1: Arrays'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_264sc_gncA4/ShYC89ZvTvI/AAAAAAAAAQg/1qye-HEjWcE/s72-c/Session8-arrayrepresentation.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-8645084582753370051</id><published>2009-05-22T08:51:00.025+08:00</published><updated>2009-08-07T22:14:19.722+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Computer-aided Learning Multiplication Problem'/><title type='text'>Tutorial 7.4: Computer-aided Learning Multiplication Problem</title><content type='html'>&lt;span style="color: rgb(173, 215, 107); font-weight: bold;font-size:130%;" &gt;PROBLEM&lt;/span&gt;&lt;br /&gt;We are writing a program that will aid an elementary school student learns multiplication. Use &lt;span style="color: rgb(51, 102, 255);"&gt;random function to generate positive one digit integers&lt;/span&gt; and it should display questions of multiplication such as:&lt;br /&gt;&lt;br /&gt;How much is 5 x 8 ?&lt;br /&gt;&lt;br /&gt;The student then input the answer. The program should &lt;span style="color: rgb(51, 102, 255);"&gt;check the answer and response with correct or wrong message&lt;/span&gt;. Then another multiplication question is displayed. The &lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;process should be repeated until -1 is inputted&lt;/span&gt; by the student meaning to exit the program.  Finally the program displays the number of correct answer and questions asked.&lt;br /&gt;&lt;br /&gt;The program also should have &lt;span style="color: rgb(51, 102, 255);"&gt;three level of difficulties&lt;/span&gt; of question. The first level is multiplication of two integers. As the level goes up, the multiplication question consists of three integers and four integers for the highest level. The program should be able to &lt;span style="color: rgb(51, 102, 255);"&gt;adjust the level difficulty automatically&lt;/span&gt; according to the performance of the student. For example it should increase the level if the student able to answer correctly for five consecutive questions and vice-versa.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(173, 215, 107);"&gt;SOLUTION&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;PROGRAM ALGORITHM (FLOW OF PROGRAM)&lt;/span&gt;&lt;br /&gt;1. Display user instructions&lt;br /&gt;2. Display a multiplication question and compute the answer&lt;br /&gt;3. Get data: user answer&lt;br /&gt;4. Check the user answer with the computed answer&lt;br /&gt;5. Determine the level of difficulty&lt;br /&gt;6. Display the performance of the user&lt;br /&gt;&lt;br /&gt;Steps 2-5 are repeated until the user exit the program.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 102, 0); font-weight: bold;"&gt;PROGRAM DESIGN&lt;/span&gt;&lt;br /&gt;We use functions to perform all required task in the program. There are six (6) functions have been defined accordingly, display the user instructions, generate integers, print the question, read user answer and check it with the correct answer, adjust the level of difficulty and display user performance.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Design of Function PrintUserInstructions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Input Parameter&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;Program Variable&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;Return Value&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sh4oicCdyhI/AAAAAAAAASU/cGNyR_8vwI8/s1600-h/Session7-project+-+userinstruct.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 88px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sh4oicCdyhI/AAAAAAAAASU/cGNyR_8vwI8/s400/Session7-project+-+userinstruct.png" alt="" id="BLOGGER_PHOTO_ID_5340750780215183890" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The definition consists of three statements to display user instructions.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Design of Function GenerateNumber&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Input Parameter&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;Program Variable&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;Return Value&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;rand() % 9 + 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sh4osi7DipI/AAAAAAAAASc/M2_8kSayIyg/s1600-h/Session7-project+-+genereate.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 58px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sh4osi7DipI/AAAAAAAAASc/M2_8kSayIyg/s400/Session7-project+-+genereate.png" alt="" id="BLOGGER_PHOTO_ID_5340750953861843602" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The expression &lt;span style="font-family:Courier New;"&gt;rand() % 9 + 1&lt;/span&gt; always returns a  value in the range 1 ≤ integer ≤ 9. Function &lt;span style="font-family:courier new;"&gt;rand()&lt;/span&gt; returns a pseudo-random number each time it is invoked. Pseudo-random number is a sequence of numbers that appears to be random that is generated using an initial value (seed). For a given seed, the sequence is always the same. If we use function &lt;span style="font-family:courier new;"&gt;rand()&lt;/span&gt; with the default seed, we will always get the same sequence. Therefore, in order to obtain a random number, we have to randomize the seed.&lt;br /&gt;&lt;br /&gt;In C, there is a function called &lt;span style="font-family:courier new;"&gt;srand()&lt;/span&gt; that can be used to initialize the pseudo-random generator by supplying a seed value as an argument to it. Now what we have to do is to supply a different value each time the program is run. This can be achieved by using function &lt;span style="font-family:courier new;"&gt;time()&lt;/span&gt; which returns the number of seconds that have passed since 00:00:00 GMT January 1, 1970.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Design of Function PrintQuestion&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Input Parameter&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int level /* level of difficulty */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Program Variables&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int i /* loop counter */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int num /*store generated integer */&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int ans /* store the computed answer */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Return Value&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int ans /* store the computed answer */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sh4pOH5xIJI/AAAAAAAAASk/xB9CwYClQrI/s1600-h/Session7-project+-+printquestion.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 205px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sh4pOH5xIJI/AAAAAAAAASk/xB9CwYClQrI/s400/Session7-project+-+printquestion.png" alt="" id="BLOGGER_PHOTO_ID_5340751530724237458" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Function PrintQuestion uses &lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; loop statement to print the multiplication question. In each iteration, an integer is generated by calling function &lt;span style="font-family:courier new;"&gt;GenerateNumber&lt;/span&gt; and multiplied with variable &lt;span style="font-family:courier new;"&gt;ans&lt;/span&gt;. The loop condition uses &lt;span style="font-family:courier new;"&gt;level&lt;/span&gt; (function's argument) in the loop condition. Initially, &lt;span style="font-family:courier new;"&gt;level&lt;/span&gt; has the value of 1 (level 1), therefore the loop is repeated twice which means the multiplication question will be consisted of two numbers.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Design of Function InputAnswer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Input Parameter&lt;br /&gt;int correct_ans /* store the correct answer */&lt;br /&gt;&lt;br /&gt;Program Variable&lt;br /&gt;int user_ans /* store the user answer */&lt;br /&gt;&lt;br /&gt;Global Variables&lt;br /&gt;int cnt_question /* count the total questions have been asked */&lt;br /&gt;int cnt_true /* count total true answer */&lt;br /&gt;int cnt_consecutive_true /* count consecutive true answer */&lt;br /&gt;int cnt_consecutive_false /* count consecutive false answer */&lt;br /&gt;&lt;br /&gt;Return Value&lt;br /&gt;QUIT 0&lt;br /&gt;CONT 1&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sh4pWJejhdI/AAAAAAAAASs/nLgHw-mWGCA/s1600-h/Session7-project+-+inputans.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 309px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sh4pWJejhdI/AAAAAAAAASs/nLgHw-mWGCA/s400/Session7-project+-+inputans.png" alt="" id="BLOGGER_PHOTO_ID_5340751668585924050" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;User answer is read by using scanf and stored in variable user_ans. Then user_ans is tested. If the value is -1, symbolic constant QUIT is returned. Else variable cnt_question is incremented and user_ans is tested. If user_ans is equal to correct_ans, variables cnt_true and cnt_consecutive_true are incremented and zero is assigned to cnt_consecutive_false.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Design of Function AdjustDifficulty&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Input Parameter&lt;br /&gt;int level&lt;br /&gt;&lt;br /&gt;Program Variable&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;Return Value&lt;br /&gt;int level&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sh4pgRHdtbI/AAAAAAAAAS0/B3wexwfcEtw/s1600-h/Session7-project+-+adjustdiff.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 177px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sh4pgRHdtbI/AAAAAAAAAS0/B3wexwfcEtw/s400/Session7-project+-+adjustdiff.png" alt="" id="BLOGGER_PHOTO_ID_5340751842435249586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Difficulty level is adjusted based on the value of variables cnt_consecutive_true and cnt_consecutive_false.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Design of Function PrintResult&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Input Parameter&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;Program Variable&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;Return Value&lt;br /&gt;None&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sh4pzxf0RyI/AAAAAAAAATE/Dz21UenadhY/s1600-h/Session7-project+-+printresult.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 88px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sh4pzxf0RyI/AAAAAAAAATE/Dz21UenadhY/s400/Session7-project+-+printresult.png" alt="" id="BLOGGER_PHOTO_ID_5340752177544840994" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The definition consists of two statements to display the total number of correct answers and total number of questions asked.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(173, 215, 107);"&gt;IMPLEMENTATION&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Begin by writing the #define directives for the constant data and global variables. In the main(), declare the variables for correct answer, level of difficulty and loop control variable. Then start coding each program algorithm steps. Call function PrintUserInstructions to display the user instruction/prompt. Then call the functions PrintQuestion, InputAnswer and AdjustDifficulty. These functions should be placed in the body of the program loop since they will be repeated until the user wants to exit.  Finally call the function PrintResult to display the result. Don't forget to use comments in your program so as you won't get lost. Good luck and Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-8645084582753370051?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/8645084582753370051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-74-computer-aided-learning_22.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/8645084582753370051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/8645084582753370051'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-74-computer-aided-learning_22.html' title='Tutorial 7.4: Computer-aided Learning Multiplication Problem'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_264sc_gncA4/Sh4oicCdyhI/AAAAAAAAASU/cGNyR_8vwI8/s72-c/Session7-project+-+userinstruct.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-3823191433050346207</id><published>2009-05-21T17:47:00.004+08:00</published><updated>2009-06-10T16:31:26.792+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Defining a Function'/><category scheme='http://www.blogger.com/atom/ns#' term='Call-by-value'/><title type='text'>Tutorial 7.3: Defining a Function</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Defining a Function&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Function definition consists of two parts, the function header and the function body (block). The function header specifies the function's return value type, function name and function parameters. The function body defines the operation that the function performs when it is called. The general form of a function definition is as follows.&lt;br /&gt;&lt;br /&gt;return-type function-name (parameters)&lt;br /&gt;{&lt;br /&gt;declarations and statements;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The &lt;span style="color: rgb(255, 0, 0);"&gt;function-name&lt;/span&gt; can be any valid identifier that is not a keyword such as &lt;span style="font-family:courier new;"&gt;int&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;break&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;char&lt;/span&gt; etc. Of course you can't use a name that already been assigned to another function. The &lt;span style="color: rgb(255, 0, 0);"&gt;parameters&lt;/span&gt; is the list of variable names and their types that carry the values received by the function from the caller. The values supplied to the function is called arguments. The &lt;span style="color: rgb(255, 0, 0);"&gt;return-type&lt;/span&gt; specifies the type of the value returned by the function. The type of value can be specified as any of the available type in C. If the return-type is omitted, &lt;span style="font-family:courier new;"&gt;int&lt;/span&gt; is assumed. The void return-type indicates that the function does not returns a value.&lt;br /&gt;&lt;br /&gt;The following program uses a function GetAverage to compute an average of three values.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/ShUevd7Y9zI/AAAAAAAAAPw/u-z2siNg3b0/s1600-h/Session7-deffunc.png"&gt;&lt;img style="cursor: pointer; width: 376px; height: 338px;" src="http://1.bp.blogspot.com/_264sc_gncA4/ShUevd7Y9zI/AAAAAAAAAPw/u-z2siNg3b0/s400/Session7-deffunc.png" alt="" id="BLOGGER_PHOTO_ID_5338206734154004274" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;The average is 20.433334&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the pre-processor section, we have the following line.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/ShUUOIXN0BI/AAAAAAAAAPg/Zw0kG5mC3fc/s1600-h/Session7-deffunc+-+1.png"&gt;&lt;img style="cursor: pointer; width: 375px; height: 16px;" src="http://1.bp.blogspot.com/_264sc_gncA4/ShUUOIXN0BI/AAAAAAAAAPg/Zw0kG5mC3fc/s400/Session7-deffunc+-+1.png" alt="" id="BLOGGER_PHOTO_ID_5338195166313173010" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This is a function prototype. It is there to tell the compiler the specification of a function. The function prototype includes specification for the return type, the parameters and the function name.  Basically function prototype is the same as the function header plus the semicolon at the end.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/ShUSdO5cC7I/AAAAAAAAAPI/hXJpKCcWbLg/s1600-h/Session7-deffunc+-+2.png"&gt;&lt;img style="cursor: pointer; width: 375px; height: 87px;" src="http://4.bp.blogspot.com/_264sc_gncA4/ShUSdO5cC7I/AAAAAAAAAPI/hXJpKCcWbLg/s400/Session7-deffunc+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5338193226742107058" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Lets look at the function definition of &lt;span style="font-family:courier new;"&gt;GetAverage&lt;/span&gt;. The function has three parameters namely &lt;span style="font-family:courier new;"&gt;num1&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;num2 &lt;/span&gt;and &lt;span style="font-family:courier new;"&gt;num3 &lt;/span&gt;which are of type &lt;span style="font-family:courier new;"&gt;float&lt;/span&gt;. It is defined to computes the average of three values and returns a &lt;span style="font-family:courier new;"&gt;float &lt;/span&gt;type value. The &lt;span style="font-family:courier new;"&gt;return&lt;/span&gt; statement is used when the function is required to return a value. If the function is defined not to return a value, we are not required to put the return statement because the control is returned simply when the close brace is reached. Note that the return value should be of the same type as the declared return type in the function header.&lt;br /&gt;&lt;br /&gt;As usual, in the function main(), we have variables declaration and assignment. In this case we have three float variables. Then we have the function call statement.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/ShUexyKH8NI/AAAAAAAAAP4/HUxVriHIZf8/s1600-h/Session7-deffunc+-+3.png"&gt;&lt;img style="cursor: pointer; width: 376px; height: 16px;" src="http://2.bp.blogspot.com/_264sc_gncA4/ShUexyKH8NI/AAAAAAAAAP4/HUxVriHIZf8/s400/Session7-deffunc+-+3.png" alt="" id="BLOGGER_PHOTO_ID_5338206773944250578" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We simply use the function's name followed by the arguments to be supplied to the function to call a function. It is important to note that the supplied arguments must be of the same type as the expected type. When the arguments are supplied to a function, copies of the values in &lt;span style="font-family:courier new;"&gt;n1&lt;/span&gt;, n2 and &lt;span style="font-family:courier new;"&gt;n3&lt;/span&gt; are made for the function. The copies are then stored in &lt;span style="font-family:courier new;"&gt;num1&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;num2&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;num3&lt;/span&gt; which have been declared in the function header. This means the function can't modifies the values in &lt;span style="font-family:courier new;"&gt;n1&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;n2&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;n3&lt;/span&gt;. This mechanism is called &lt;span style="color: rgb(255, 0, 0);"&gt;call-by-value&lt;/span&gt;. There is another mechanism called &lt;span style="color: rgb(255, 0, 0);"&gt;call-by-reference&lt;/span&gt;. These two mechanism will be discussed in the next section. The result (returned value) of the function is assigned to variable &lt;span style="font-family:courier new;"&gt;res&lt;/span&gt;. Finally the value of &lt;span style="font-family:courier new;"&gt;res&lt;/span&gt; is displayed using &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-81-arrays.html"&gt;Arrays&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-3823191433050346207?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/3823191433050346207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-72-defining-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/3823191433050346207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/3823191433050346207'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-72-defining-function.html' title='Tutorial 7.3: Defining a Function'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_264sc_gncA4/ShUevd7Y9zI/AAAAAAAAAPw/u-z2siNg3b0/s72-c/Session7-deffunc.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-4440593439472498601</id><published>2009-05-21T11:55:00.005+08:00</published><updated>2009-06-10T16:31:44.975+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Variable Scope'/><category scheme='http://www.blogger.com/atom/ns#' term='Function Execution Sequence'/><category scheme='http://www.blogger.com/atom/ns#' term='Global Variable'/><title type='text'>Tutorial 7.2: Variable Scope and Sequence of Execution</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Variable Scope&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;All examples that have been presented in the previous tutorials declared variables in the block of function main(). These variables are known only within the block of function main() which means, the variables are not accessible outside of the block. This is also applied to variables which are defined within a block that is inside other block. But variables which are defined in the outer block are accessible in the inner block. This is illustrated in the following example.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/ShJGsSS9HrI/AAAAAAAAAN4/uMPJiizxopQ/s1600-h/Session7-varscope.png"&gt;&lt;img style="cursor: pointer; width: 235px; height: 192px;" src="http://3.bp.blogspot.com/_264sc_gncA4/ShJGsSS9HrI/AAAAAAAAAN4/uMPJiizxopQ/s400/Session7-varscope.png" alt="" id="BLOGGER_PHOTO_ID_5337406235026988722" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the example there are two variables declared,. Variable a is declared within function main() block and variable b is declared within while loop block. a is the outer block variable therefore it is accessible within inner block. But b is not accessible in the outer block because it is while loop variable. Thus if you try to print the value of b outside the while loop block, you will get an error message when you compile the program.&lt;br /&gt;&lt;br /&gt;Variables declared outside any function is called &lt;span style="color: rgb(255, 0, 0);"&gt;global variables&lt;/span&gt;. A global variable is a variable that can be accessed in any function. Global variables are declared in the normal way except that (normally) they are declared before function main().&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Sequence of Execution&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Before we discuss the details on how to define a function, lets look the sequence of execution when functions are invoked. When a function is invoked, the code within the function's body is executed. Then execution continues from the point at which the function was called. The operation is illustrated in the following figure.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/ShSyeEsO9cI/AAAAAAAAAO4/fTJBd9Mu2rs/s1600-h/Session7-functoperation.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 212px;" src="http://1.bp.blogspot.com/_264sc_gncA4/ShSyeEsO9cI/AAAAAAAAAO4/fTJBd9Mu2rs/s400/Session7-functoperation.png" alt="" id="BLOGGER_PHOTO_ID_5338087688065971650" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For example, the function main() calls function1. The statements within the block of function1 are executed. When it reaches at the end of the block, it returns to the main function and continues at the point at which the function1 was called. Similarly, a function can be invoked by another function. The sequence of execution is the same as when the main function calls a function. This is illustrated in the figure where function3 calls function4.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a style="color: rgb(0, 0, 153);" href="http://begincprogram.blogspot.com/2009/05/tutorial-72-defining-function.html"&gt;Defining a Function&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-4440593439472498601?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/4440593439472498601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-72-variable-scope-and-sequence.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/4440593439472498601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/4440593439472498601'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-72-variable-scope-and-sequence.html' title='Tutorial 7.2: Variable Scope and Sequence of Execution'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_264sc_gncA4/ShJGsSS9HrI/AAAAAAAAAN4/uMPJiizxopQ/s72-c/Session7-varscope.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-6642355739013275987</id><published>2009-05-21T09:00:00.003+08:00</published><updated>2009-06-10T16:34:16.220+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Introduction to Functions'/><title type='text'>Tutorial 7.1: Functions</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Programs that solve the real-world problem are usually consist of thousands (or more) of lines of code. In that case, it is not easy to develop, maintain and manage a large source code in a single function - main(). So when we are writing a big program, the best way to deal with it is to break the large program into smaller sets of statements (functions) according to their tasks. For example we could define functions that performs the printing of user instructions, reading inputs from user, calculating equation and etc . Whenever we need to do something, we just call the relevant function in the main() that do the specific task. In that case, our program will be neat and tidy and errors can be easily detected and solved.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A) Program with no functions&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/ShD_6Cr26qI/AAAAAAAAANg/g2UFsYnzth0/s1600-h/Session7-notusefuncA.png"&gt;&lt;img style="cursor: pointer; width: 333px; height: 288px;" src="http://1.bp.blogspot.com/_264sc_gncA4/ShD_6Cr26qI/AAAAAAAAANg/g2UFsYnzth0/s400/Session7-notusefuncA.png" alt="" id="BLOGGER_PHOTO_ID_5337046931052358306" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/ShEAIz-v04I/AAAAAAAAANw/mOpHtVcGgG4/s1600-h/Session7-notusefuncB.png"&gt;&lt;img style="cursor: pointer; width: 333px; height: 209px;" src="http://2.bp.blogspot.com/_264sc_gncA4/ShEAIz-v04I/AAAAAAAAANw/mOpHtVcGgG4/s400/Session7-notusefuncB.png" alt="" id="BLOGGER_PHOTO_ID_5337047184803091330" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;B) Program with functions&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/ShD9ztzyI8I/AAAAAAAAANQ/JMwb8l5KUoM/s1600-h/Session7-usefuncA.png"&gt;&lt;img style="cursor: pointer; width: 320px; height: 336px;" src="http://3.bp.blogspot.com/_264sc_gncA4/ShD9ztzyI8I/AAAAAAAAANQ/JMwb8l5KUoM/s400/Session7-usefuncA.png" alt="" id="BLOGGER_PHOTO_ID_5337044623345984450" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/ShOxJqrlIbI/AAAAAAAAAOA/VndYn2mliKE/s1600-h/Session7-usefuncB.png"&gt;&lt;img style="cursor: pointer; width: 367px; height: 371px;" src="http://1.bp.blogspot.com/_264sc_gncA4/ShOxJqrlIbI/AAAAAAAAAOA/VndYn2mliKE/s400/Session7-usefuncB.png" alt="" id="BLOGGER_PHOTO_ID_5337804762998186418" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Enter scores for class A (-1 to end):&lt;br /&gt;75&lt;br /&gt;85&lt;br /&gt;64&lt;br /&gt;-1&lt;br /&gt;Class A average is 74.67&lt;br /&gt;&lt;br /&gt;Enter scores for class B (-1 to end):&lt;br /&gt;37&lt;br /&gt;97&lt;br /&gt;71&lt;br /&gt;-1&lt;br /&gt;Class B average is 68.33&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Both program A and B are written to perform the same task which is to calculate average score for two classes. But program A does not use functions and program B uses function. As you can see in program B, the codes of user instructions, read inputs, calculate and display the average are segmented into functions. In function &lt;span style="font-family:courier new;"&gt;main()&lt;/span&gt;, we invoke/call the relevant functions to perform the required tasks.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-72-variable-scope-and-sequence.html"&gt;Variable Scope and Sequence of Execution&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-6642355739013275987?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/6642355739013275987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-71-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/6642355739013275987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/6642355739013275987'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-71-functions.html' title='Tutorial 7.1: Functions'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_264sc_gncA4/ShD_6Cr26qI/AAAAAAAAANg/g2UFsYnzth0/s72-c/Session7-notusefuncA.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-1304064780470118460</id><published>2009-05-19T13:43:00.006+08:00</published><updated>2009-06-10T16:41:40.975+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='break'/><category scheme='http://www.blogger.com/atom/ns#' term='Infinite Loop'/><category scheme='http://www.blogger.com/atom/ns#' term='Repetition Structure'/><title type='text'>Tutorial 6.5: Infinite Loop</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Infinite Loop&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Infinite loop is a repetition structure that loops forever, either due to it contains no condition that can cause the loop to be terminated or having condition that can never be satisfied. Let us see how &lt;span style="font-family:courier new;"&gt;while&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; loop statement can be set up to get an infinite loop.&lt;br /&gt;&lt;br /&gt;Having an expression  within the parenthesis of &lt;span style="font-family:courier new;"&gt;while&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; (second expression of &lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; loop) that always returns true (non-zero value) can result an infinite loop. The following programs are example of infinite loop of &lt;span style="font-family:courier new;"&gt;while&lt;/span&gt;,&lt;span style="font-family:courier new;"&gt; do while&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; repetition structure.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg-23rKyhdI/AAAAAAAAALQ/kHTAb8D-cTY/s1600-h/Session6-infinite+while.png"&gt;&lt;img style="cursor: pointer; width: 320px; height: 193px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg-23rKyhdI/AAAAAAAAALQ/kHTAb8D-cTY/s400/Session6-infinite+while.png" alt="" id="BLOGGER_PHOTO_ID_5336685151054366162" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg-27GZdnQI/AAAAAAAAALY/p3KFnUgSXaQ/s1600-h/Session6-infinite+dowhile.png"&gt;&lt;img style="cursor: pointer; width: 320px; height: 193px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg-27GZdnQI/AAAAAAAAALY/p3KFnUgSXaQ/s400/Session6-infinite+dowhile.png" alt="" id="BLOGGER_PHOTO_ID_5336685209903275266" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg-3OviH2DI/AAAAAAAAALo/mb5fW1IWWrU/s1600-h/Session6-infinite+for.png"&gt;&lt;img style="cursor: pointer; width: 237px; height: 195px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg-3OviH2DI/AAAAAAAAALo/mb5fW1IWWrU/s400/Session6-infinite+for.png" alt="" id="BLOGGER_PHOTO_ID_5336685547362965554" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The loop condition (expression)  is set to 1, resulting an infinite loop.&lt;br /&gt;&lt;br /&gt;Sometimes infinite loop can be useful,  for example when we want to write a program that computes the average of an arbitrary number of integers. A sample program is given below. The program should be able to allow the user to input any number of integers until he is satisfied. In this case, we have to define an infinite loop so as the program can perform the specific task. But what can we do to have the means of exiting the infinite loop? The answer is the statements in the loop's body must contains the means of exiting from the loop. Remember keyword &lt;span style="font-family:courier new;"&gt;break&lt;/span&gt; from &lt;a href="http://begincprogram.blogspot.com/2009/05/lesson-54-selection-structure.html"&gt;Tutorial 5.4&lt;/a&gt;. We have seen how &lt;span style="font-family:courier new;"&gt;break&lt;/span&gt; can be used to jump out of &lt;span style="font-family:courier new;"&gt;switch&lt;/span&gt; selection bypassing the following statements. Similarly &lt;span style="font-family:courier new;"&gt;break&lt;/span&gt; can be used to exit a loop from any point of its body.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg_C0NUgwtI/AAAAAAAAALw/qa2sS1lxxQg/s1600-h/Session6-infinite+average.png"&gt;&lt;img style="cursor: pointer; width: 368px; height: 400px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg_C0NUgwtI/AAAAAAAAALw/qa2sS1lxxQg/s400/Session6-infinite+average.png" alt="" id="BLOGGER_PHOTO_ID_5336698285642007250" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;This program computes the average of any number of integers.&lt;br /&gt;Enter integers (-1 to stop input):&lt;br /&gt;10&lt;br /&gt;5&lt;br /&gt;7&lt;br /&gt;-1&lt;br /&gt;The average is 7.33&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg_ELKNp3RI/AAAAAAAAAL4/A5Hr_NKzYd8/s1600-h/Session6-infinite+average+-+1.png"&gt;&lt;img style="cursor: pointer; width: 369px; height: 64px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg_ELKNp3RI/AAAAAAAAAL4/A5Hr_NKzYd8/s400/Session6-infinite+average+-+1.png" alt="" id="BLOGGER_PHOTO_ID_5336699779456556306" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here we declare four (4) variables namely &lt;span style="font-family:courier new;"&gt;i&lt;/span&gt;,&lt;span style="font-family:courier new;"&gt; num&lt;/span&gt;,&lt;span style="font-family:courier new;"&gt; sum &lt;/span&gt;and&lt;span style="font-family:courier new;"&gt; average&lt;/span&gt;. Variable &lt;span style="font-family:courier new;"&gt;i&lt;/span&gt; is used to count the number of integers entered by the user. The entered integer is stored in variable &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt;. The summation of all integers is stored in variable sum and lastly variable average is used to store the average.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg_EPYrHjcI/AAAAAAAAAMA/ToHt0-MdeeE/s1600-h/Session6-infinite+average+-+2.png"&gt;&lt;img style="cursor: pointer; width: 369px; height: 50px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg_EPYrHjcI/AAAAAAAAAMA/ToHt0-MdeeE/s400/Session6-infinite+average+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5336699852057710018" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Then we display the user instruction using &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt;. We inform the user to input -1 if he wants to end input process.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg_ETdqb63I/AAAAAAAAAMI/IDnsDMJlTGo/s1600-h/Session6-infinite+average+-+3.png"&gt;&lt;img style="cursor: pointer; width: 368px; height: 145px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg_ETdqb63I/AAAAAAAAAMI/IDnsDMJlTGo/s400/Session6-infinite+average+-+3.png" alt="" id="BLOGGER_PHOTO_ID_5336699922116504434" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We set up an the loop using &lt;span style="font-family:courier new;"&gt;while&lt;/span&gt; statement. Since loop condition has the value of &lt;span style="font-family:courier new;"&gt;1&lt;/span&gt;, the block of statements will be repeated forever. In the body of the loop, we have read input from user statement. The input integer is stored in variable &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt;. Then we compare the value of &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt; with -1. If the comparison is true indicating the user wants to end the input process, &lt;span style="font-family:courier new;"&gt;break&lt;/span&gt; statement will be executed. Else the &lt;span style="font-family:courier new;"&gt;i&lt;/span&gt; is incremented and the value entered is added to variable &lt;span style="font-family:courier new;"&gt;sum&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg_EXbYw60I/AAAAAAAAAMQ/paXnVZMuVIs/s1600-h/Session6-infinite+average+-+4.png"&gt;&lt;img style="cursor: pointer; width: 368px; height: 33px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg_EXbYw60I/AAAAAAAAAMQ/paXnVZMuVIs/s400/Session6-infinite+average+-+4.png" alt="" id="BLOGGER_PHOTO_ID_5336699990224988994" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Finally we calculate the average and display the result.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-71-functions.html"&gt;Functions&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-1304064780470118460?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/1304064780470118460/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-65-infinite-loop.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1304064780470118460'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1304064780470118460'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-65-infinite-loop.html' title='Tutorial 6.5: Infinite Loop'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_264sc_gncA4/Sg-23rKyhdI/AAAAAAAAALQ/kHTAb8D-cTY/s72-c/Session6-infinite+while.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-1556974684229997953</id><published>2009-05-18T23:46:00.005+08:00</published><updated>2009-06-10T16:41:50.774+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Nested Loop'/><category scheme='http://www.blogger.com/atom/ns#' term='Repetition Structure'/><title type='text'>Tutorial 6.4: Nested Loop</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Nested Loop&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Remember &lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-53-nested-if-selection.html"&gt;nested &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt;&lt;/a&gt;, the same can be applied to repetition structure. A loop within a loop is called nested loop. Any type of loop can be placed in any type of  loop. Its means, you can put a while loop in a for loop, do while loop in a while loop etc. The following is an example of nested loop.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg7p4RaXcyI/AAAAAAAAAKA/wCwYaXSPQB4/s1600-h/Session6-nested+loop.png"&gt;&lt;img style="cursor: pointer; width: 263px; height: 257px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg7p4RaXcyI/AAAAAAAAAKA/wCwYaXSPQB4/s400/Session6-nested+loop.png" alt="" id="BLOGGER_PHOTO_ID_5336459761436554018" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;1               1&lt;br /&gt;2               3&lt;br /&gt;3               6&lt;br /&gt;4               10&lt;br /&gt;5               15&lt;br /&gt;6               21&lt;br /&gt;7               28&lt;br /&gt;8               36&lt;br /&gt;9               45&lt;br /&gt;10              55&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The program computes the sum of all numbers from 1 up to the value of j which is 10. Lets look at the loop structure.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sg7qJiF9fII/AAAAAAAAAKI/kSZkb9HKNuU/s1600-h/Session6-nested+loop+-+2.png"&gt;&lt;img style="cursor: pointer; width: 263px; height: 130px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sg7qJiF9fII/AAAAAAAAAKI/kSZkb9HKNuU/s400/Session6-nested+loop+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5336460057972145282" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The for loop is called the outer loop and the do while loop is called inner loop. Each time outer loop is repeated, inner loop will be executed and all its iteration are performed. This means, inner loop is executed or all its iteration are completed 10 in this example since the outer loop is repeated 10 times.&lt;br /&gt;&lt;br /&gt;The for loop begins by assigning value of 1 to i. The loop condition is i &amp;lt; 11 thus the for loop will repeat for 10 times. For each iteration of for loop, variable sum is initialise to 0 and the do while is executed.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sg7tjC_vv2I/AAAAAAAAAKQ/vQfHkMybnRw/s1600-h/Session6-nested+loop+-+3.png"&gt;&lt;img style="cursor: pointer; width: 263px; height: 51px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sg7tjC_vv2I/AAAAAAAAAKQ/vQfHkMybnRw/s400/Session6-nested+loop+-+3.png" alt="" id="BLOGGER_PHOTO_ID_5336463794836062050" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The do while loop computes the sum of all values of j each time j is incremented until the current value of i. You may wonder what is the statement&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg7uhSoLGkI/AAAAAAAAAKY/yd8d8COc9DE/s1600-h/Session6-nested+loop+-+4.png"&gt;&lt;img style="cursor: pointer; width: 263px; height: 16px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg7uhSoLGkI/AAAAAAAAAKY/yd8d8COc9DE/s400/Session6-nested+loop+-+4.png" alt="" id="BLOGGER_PHOTO_ID_5336464864184048194" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;is doing. Actually that statement is equivalent to&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg7vQahPl9I/AAAAAAAAAKg/WP-IxGgJLaY/s1600-h/Session6-nested+loop+-+5.png"&gt;&lt;img style="cursor: pointer; width: 262px; height: 32px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg7vQahPl9I/AAAAAAAAAKg/WP-IxGgJLaY/s400/Session6-nested+loop+-+5.png" alt="" id="BLOGGER_PHOTO_ID_5336465673756317650" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 102, 102);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-65-infinite-loop.html"&gt;Infinite Loop&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-1556974684229997953?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/1556974684229997953/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-64-nested-loop.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1556974684229997953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1556974684229997953'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-64-nested-loop.html' title='Tutorial 6.4: Nested Loop'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_264sc_gncA4/Sg7p4RaXcyI/AAAAAAAAAKA/wCwYaXSPQB4/s72-c/Session6-nested+loop.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-7308521588004595362</id><published>2009-05-18T12:03:00.004+08:00</published><updated>2009-06-10T16:38:48.406+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='for Loop'/><category scheme='http://www.blogger.com/atom/ns#' term='Repetition Structure'/><title type='text'>Tutorial 6.3: for Repetition Structure</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;span&gt;&lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; Loop Statement&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Unlike while and do while statement, for statement handles all the details such as variable initialisation, variable update and loop condition within single parantheses. If you still confuse with what i mean, lets revise the while loop example.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg1K-xTqhUI/AAAAAAAAAG4/Hh60pPadwek/s1600-h/Session6-while+-+3.png"&gt;&lt;img style="cursor: pointer; width: 300px; height: 82px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg1K-xTqhUI/AAAAAAAAAG4/Hh60pPadwek/s400/Session6-while+-+3.png" alt="" id="BLOGGER_PHOTO_ID_5336003575752066370" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;As you can see, the statements to control the loop operation are separated. In the for statement, these statements are combined together. Lets look at the for statement structure to have better understanding.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;for ( variable initialisation; loop condition; variable update ) {&lt;br /&gt;...statements...&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;for statement structure has three (3) fields which are variable initialisation, loop condition and variable update. These fields in the for statement are optional. we may omit variable initialisation and place it elsewhere in the program for example before for statement. If loop condition is omitted, C will assume that the condition is true thus resulting an indefinite loop. Variable update may be ommited if we want to place it in the body of for statement.&lt;br /&gt;&lt;br /&gt;An example of &lt;span style="font-family:courier new;"&gt;for &lt;/span&gt;statement is given. The purpose of this program is to display zero (0) to nine (9).&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg1YxpctL4I/AAAAAAAAAHY/k4iJNVDlWaw/s1600-h/Session6-for.png"&gt;&lt;img style="cursor: pointer; width: 291px; height: 162px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg1YxpctL4I/AAAAAAAAAHY/k4iJNVDlWaw/s400/Session6-for.png" alt="" id="BLOGGER_PHOTO_ID_5336018743466995586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As usual, we declare an integer variable count which acts as the loop counter. We do not initialise the variable unlike while and do while statement because it will be taken care of in the for statement.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sg1Z2p3OSkI/AAAAAAAAAHg/4suSEhGL4iw/s1600-h/Session6-for+-+2.png"&gt;&lt;img style="cursor: pointer; width: 291px; height: 49px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sg1Z2p3OSkI/AAAAAAAAAHg/4suSEhGL4iw/s400/Session6-for+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5336019928989190722" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here we have the for repetition structure. The operation of the loop is controlled by the three expression between the for statement parantheses. In the variable initialisation field, we initialise variable to 0. The specified loop condition is count less than 10&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-64-nested-loop.html"&gt;Nested Loop&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-7308521588004595362?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/7308521588004595362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-63-for-repetition-structure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/7308521588004595362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/7308521588004595362'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-63-for-repetition-structure.html' title='Tutorial 6.3: for Repetition Structure'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_264sc_gncA4/Sg1K-xTqhUI/AAAAAAAAAG4/Hh60pPadwek/s72-c/Session6-while+-+3.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-5685039371588784261</id><published>2009-05-18T11:06:00.003+08:00</published><updated>2009-06-10T16:37:31.858+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='do while Loop'/><category scheme='http://www.blogger.com/atom/ns#' term='Repetition Structure'/><title type='text'>Tutorial 6.2: do while Repetition Structure</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;span&gt;&lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; Loop&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; loop is similar to the &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop. In the &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop, the loop condition is tested at the beginning of the loop. The &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; loop tests the loop condition at the end of the loop structure or after the body of the loop is executed. Thus in &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; loop, the compounded statement will be executed at least once.&lt;br /&gt;&lt;br /&gt;Lets look at an example of &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; loop.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg1I0bvdM8I/AAAAAAAAAGo/5z_b52In0eQ/s1600-h/Session6-dowhile.png"&gt;&lt;img style="cursor: pointer; width: 214px; height: 176px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg1I0bvdM8I/AAAAAAAAAGo/5z_b52In0eQ/s400/Session6-dowhile.png" alt="" id="BLOGGER_PHOTO_ID_5336001199141106626" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is also a very simple program of &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; loop. The function of the program is exactly the same as the example of &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop. We skip the counter declaration and initialisation since it is already covered in the previous example. We go straight to the &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; loop structure.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg1I6iZZm2I/AAAAAAAAAGw/Yr-lv8T3SeQ/s1600-h/Session6-dowhile+-+2.png"&gt;&lt;img style="cursor: pointer; width: 214px; height: 66px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg1I6iZZm2I/AAAAAAAAAGw/Yr-lv8T3SeQ/s400/Session6-dowhile+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5336001304006859618" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Similarly, it contains two (2) statements action printing the value of count and ++count. Lets go through it line-by-line. When the &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; is executed, it begins by executing the &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; function. Thus &lt;span style="font-family:courier new;"&gt;count &lt;/span&gt;is displayed on the monitor screen. Then &lt;span style="font-family:courier new;"&gt;count &lt;/span&gt;is incremented and it reaches the brace at the end of the loop. Here loop condition is tested and if it is true, it will go back up to the beginning and the body of the loop will be executed again. This action continues until the condition is false.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-63-for-repetition-structure.html"&gt;for loop&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-5685039371588784261?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/5685039371588784261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-62-do-while-repetition.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/5685039371588784261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/5685039371588784261'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-62-do-while-repetition.html' title='Tutorial 6.2: do while Repetition Structure'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_264sc_gncA4/Sg1I0bvdM8I/AAAAAAAAAGo/5z_b52In0eQ/s72-c/Session6-dowhile.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-3092621484930463983</id><published>2009-05-17T22:27:00.004+08:00</published><updated>2009-07-13T14:40:18.676+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='while Loop'/><category scheme='http://www.blogger.com/atom/ns#' term='Repetition Structure'/><title type='text'>Tutorial 6.1: while Repetition Structure</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;INTRODUCTION&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;In the previous tutorial, we have learned about sequence and selection structures. We know that selection structure allows us to specify how the computer will react to certain inputs. But there is still a limitation in what we can do in programming. For example what if we want to display numbers from 1 to 100? Of course we can do hundred lines of &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt;, but what if we want to repeat a thousand times of 10 statements. We would have to write ten thousand of statements to achieve it and it is possible to do it. But it is not a convenience and it would take a long time to complete. Thus the ability to specify repetition of compound statements is as important in programming. Repetition of statements execution is called loop. Looping in a program is the &lt;span style="color: rgb(51, 102, 255);"&gt;process of executing series of instruction repeatedly&lt;/span&gt; in a given number of times.&lt;br /&gt;&lt;br /&gt;There are two types of loop namely &lt;span style="color: rgb(51, 102, 255);"&gt;definite loop&lt;/span&gt; and &lt;span style="color: rgb(51, 102, 255);"&gt;indefinite loop&lt;/span&gt;. Definite loop also called counter-controlled loop is a repetition in which it will continue looping until certain condition is met. On the contrary indefinite loop has no certain condition in which it will continue looping forever. Thus statements enclosed by indefinite loop should contain the means of exiting from the loop. Typically, there are three requirements have to be specified in defining a definite loop. They are counter initialization, increment of counter and loop condition. The counter will determine how many times the loop will be executed. There are three types of repetition structure available in C namely &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop, &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; loop and &lt;span style="font-family:courier new;"&gt;for &lt;/span&gt;loop.&lt;br /&gt;&lt;br /&gt;But before going further, you should understand the concept of True and False in C. We have covered this concept in &lt;a href="http://beginningcprogramming.blogspot.com/2009/05/session-5-selection-structure.html"&gt;Tutorial 5&lt;/a&gt;. You might want to look at it if you still have not grasped the basic concept. We begin by discussing the &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop followed by &lt;span style="font-family:courier new;"&gt;do while&lt;/span&gt; loop. Then we will discuss &lt;span style="font-family:courier new;"&gt;for&lt;/span&gt; loop because I believe &lt;span style="font-family:courier new;"&gt;for&lt;span style="font-family:georgia;"&gt; &lt;/span&gt;&lt;/span&gt;loop is a bit complicated compared to the other loops.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;span style="font-family:courier new;"&gt;while&lt;/span&gt; LOOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop allows the repetition of a set of statements execution to continue for as long as a specified expression (condition) is true. When the condition becomes false, the repetition terminates and the first statement after the repetition structure is executed. Basically while loop is similar to if selection in the sense that their set of statements are executed if the condition is true. The different is &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop repeats the statement execution as long as the condition is true and if selection does not have the repetition feature.&lt;br /&gt;&lt;br /&gt;Lets look at an example to have an idea what is &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop all about.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg1IHBiBtEI/AAAAAAAAAGQ/S4vkVEJFwPE/s1600-h/Session6-while.png"&gt;&lt;img style="cursor: pointer; width: 214px; height: 177px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg1IHBiBtEI/AAAAAAAAAGQ/S4vkVEJFwPE/s400/Session6-while.png" alt="" id="BLOGGER_PHOTO_ID_5336000419011343426" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;br /&gt;9&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is a very simple &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop. It has an expression as the mechanism of repetition and a set of statements. Now lets look at the first statement.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg1IMTyiaAI/AAAAAAAAAGY/wFFCSVVOTxE/s1600-h/Session6-while+-+1.png"&gt;&lt;img style="cursor: pointer; width: 214px; height: 16px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg1IMTyiaAI/AAAAAAAAAGY/wFFCSVVOTxE/s400/Session6-while+-+1.png" alt="" id="BLOGGER_PHOTO_ID_5336000509811779586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here, we declare an integer variable &lt;span style="font-family:courier new;"&gt;count &lt;/span&gt;and initialize it to 0. Variable &lt;span style="font-family:courier new;"&gt;count &lt;/span&gt;acts as the loop counter for the &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg1IOTFlDdI/AAAAAAAAAGg/_INFgUXUic0/s1600-h/Session6-while+-+2.png"&gt;&lt;img style="cursor: pointer; width: 214px; height: 66px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg1IOTFlDdI/AAAAAAAAAGg/_INFgUXUic0/s400/Session6-while+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5336000543982947794" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now we look at our &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop. It contains two statements action printing the value of &lt;span style="font-family:courier new;"&gt;count&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;++count&lt;/span&gt;. If you are not sure what &lt;span style="font-family:courier new;"&gt;++count&lt;/span&gt; is doing, you might want to look at &lt;a href="http://beginningcprogramming.blogspot.com/2009/05/operators.html"&gt;Tutorial 4 Increment and Decrement Operators&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Lets go through it line-by-line how &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop works in this example. It begins by testing the &lt;span style="font-family:courier new;"&gt;while &lt;/span&gt;loop condition. Variable &lt;span style="font-family:courier new;"&gt;count &lt;/span&gt;has value of 0, thus the condition of count &amp;lt; 10 is true. &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; prints the value of &lt;span style="font-family:courier new;"&gt;count &lt;/span&gt;and &lt;span style="font-family:courier new;"&gt;count &lt;/span&gt;is incremented. When it reaches the close brace, it jump back up to the beginning of the loop and the condition is tested again. This process is repeated until the condition becomes false and the loop is terminated.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-62-do-while-repetition.html"&gt;do while Loop&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-3092621484930463983?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/3092621484930463983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-61-while-repetition-structure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/3092621484930463983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/3092621484930463983'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-61-while-repetition-structure.html' title='Tutorial 6.1: while Repetition Structure'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_264sc_gncA4/Sg1IHBiBtEI/AAAAAAAAAGQ/S4vkVEJFwPE/s72-c/Session6-while.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-620752507126902294</id><published>2009-05-14T19:23:00.005+08:00</published><updated>2009-08-07T22:14:02.868+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Electricity Bill Problem'/><title type='text'>Tutorial 5.5: Electricity Bill Problem</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;PROBLEM&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;We are going to write a program that computes a customer's electricity bill. The rate of charge for the first 200 unit of electricity used is RM0.218. For the following unit of electricity used is RM0.334. A penalty of 1.5% of the unpaid balance if the unpaid balance is greater than zero. Electricity unit, unpaid balance are inputted by user.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;SOLUTION&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;PROGRAM DATA REQUIREMENT&lt;/span&gt;&lt;br /&gt;List of data required in this problem. There are three (3) categories of data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Constants&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;RATELESS 0.218 /* rate of charge first 200 unit */&lt;br /&gt;RATEMORE 0.334 /* rate of charge following unit */&lt;br /&gt;PEN 0.015 /* penalty for unpaid balance */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Inputs&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int unit /* unit of electricity used */&lt;br /&gt;float UnpaidBal /* unpaid balance */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Outputs&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;float Penalty /* charge of penalty */&lt;br /&gt;float UseCharge /* charge for the current electricity use */&lt;br /&gt;float TotalBill /* total charge */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;PROGRAM ALGORITHM (FLOW OF PROGRAM)&lt;/span&gt;&lt;br /&gt;1. Display user instructions&lt;br /&gt;2. Get data: unpaid balance and electricity unit used&lt;br /&gt;3. Determine electricity unit used and compute use charge&lt;br /&gt;4. Determine unpaid balance and compute penalty&lt;br /&gt;5. Compute total charge&lt;br /&gt;6. Display the total bill amount&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;DESIGN OF COMPUTATION OF USE CHARGE&lt;/span&gt;&lt;br /&gt;The data required to compute the use charge are listed. We separate the involved data categories into Input, Process and Output.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Input Data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int unit /* unit of electricity used */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Process Data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;RATELESS 0.218 /* rate of charge first 200 unit */&lt;br /&gt;RATEMORE 0.334 /* rate of charge following unit */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Output Data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;float UseCharge /* charge for the current electricity use */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Algorithm for Computation of Use Charge&lt;/span&gt;&lt;br /&gt;We know that different rate will be used if the electricity unit used is more than 200. Thus we use if else selection to design the algorithm.&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if unit &gt; 200&lt;br /&gt;compute use charge for more than 200 unit&lt;br /&gt;else&lt;br /&gt;compute use charge for less than 200 unit&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Formula for Use Charge&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;UseCharge=(unit-200)*RATEMORE+200*RATELESS /* more than 200 */&lt;br /&gt;UseCharge=unit*RATELESS /* less than 200 */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;DESIGN OF COMPUTATION OF PENALTY&lt;/span&gt;&lt;br /&gt;The data required to compute the penalty are listed. We separate the involved data categories into Input, Process and Output.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Input Data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;float UnpaidBal /* unpaid balance */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Process Data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;PEN 0.015 /* penalty for unpaid balance */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Output Data&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;float Penalty /* charge of penalty */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Algorithm for Computation of Penalty&lt;/span&gt;&lt;br /&gt;Penalty is dealt when there is an unpaid balance. We use if selection to design the algorithm.&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if unpaid balance &gt; 0&lt;br /&gt;compute penalty&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Formula for Penalty&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Penalty=PEN*UnpaidBal&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;DESIGN OF ELECTRICITY BILL LAYOUT&lt;/span&gt;&lt;br /&gt;Displaying bill involves only input data (variables).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Input Data&lt;/span&gt;&lt;br /&gt;float Penalty&lt;br /&gt;float UnpaidBal&lt;br /&gt;float UseCharge.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Algorithm for Displaying Bill&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if unpaid balance &gt; 0&lt;br /&gt;compute penalty&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;IMPLEMENTATION&lt;/span&gt;&lt;br /&gt;Begin by writing the &lt;span style="color: rgb(255, 0, 0);"&gt;#define directives&lt;/span&gt; for the constant data. In the main(), &lt;span style="color: rgb(255, 0, 0);"&gt;declare the input and output variables&lt;/span&gt;. Then start coding each program algorithm steps. Use &lt;span style="color: rgb(255, 0, 0);"&gt;printf()&lt;/span&gt; to display the user instruction/prompt and &lt;span style="color: rgb(255, 0, 0);"&gt;scanf()&lt;/span&gt; to read the user inputs (UnpaidBal and unit). Implement the computation of use charge and penalty using &lt;span style="color: rgb(255, 0, 0);"&gt;if else selection&lt;/span&gt;. Then, use relevant &lt;span style="color: rgb(255, 0, 0);"&gt;arithmetic operators&lt;/span&gt; to construct the formulas under their corresponding if else selection. Finally use &lt;span style="color: rgb(255, 0, 0);"&gt;comments&lt;/span&gt; in your program so as you won't get lost. Good luck and Happy Coding!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-620752507126902294?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/620752507126902294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/lesson-55-electricity-bill-problem.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/620752507126902294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/620752507126902294'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/lesson-55-electricity-bill-problem.html' title='Tutorial 5.5: Electricity Bill Problem'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-7423840492939880487</id><published>2009-05-14T14:39:00.005+08:00</published><updated>2009-06-10T16:42:36.933+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='switch Statement'/><category scheme='http://www.blogger.com/atom/ns#' term='break'/><category scheme='http://www.blogger.com/atom/ns#' term='Selection Structure'/><title type='text'>Tutorial 5.4: switch Selection Structure</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;span style="font-family:courier new;"&gt;switch&lt;/span&gt; Selection Statement&lt;/span&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;switch&lt;/span&gt; statement allow us to select one from multiple options. It is especially useful when we want to write a code that makes a selection based on an expression or a variable. &lt;span style="font-family:courier new;"&gt;switch&lt;/span&gt; selection structure consists of a series of case label sand optional default case as shown below.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg1BC1xrkPI/AAAAAAAAAFo/nWK5HD3wlfA/s1600-h/Session5-switch+structure.png"&gt;&lt;img style="cursor: pointer; width: 137px; height: 226px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg1BC1xrkPI/AAAAAAAAAFo/nWK5HD3wlfA/s400/Session5-switch+structure.png" alt="" id="BLOGGER_PHOTO_ID_5335992650554904818" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;switch&lt;/span&gt; statement works by comparing the value of variable or expression within parentheses with values specified in each &lt;span style="font-family:courier new;"&gt;case&lt;/span&gt;. If there is a match, the statements following the &lt;span style="font-family:courier new;"&gt;case&lt;/span&gt; will be executed. If there is no match occurs, the &lt;span style="font-family:courier new;"&gt;default&lt;/span&gt; statement is executed. At the end of each case, keyword &lt;span style="font-family:courier new;"&gt;break&lt;/span&gt; must be placed to exit from the &lt;span style="font-family:courier new;"&gt;switch&lt;/span&gt; immediately after statements execution.&lt;br /&gt;&lt;br /&gt;Lets look at an example.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg1BLCWSwxI/AAAAAAAAAFw/MYjniafvJSQ/s1600-h/Session5-switcha.png"&gt;&lt;img style="cursor: pointer; width: 291px; height: 193px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg1BLCWSwxI/AAAAAAAAAFw/MYjniafvJSQ/s400/Session5-switcha.png" alt="" id="BLOGGER_PHOTO_ID_5335992791368647442" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg1BQ4KCIZI/AAAAAAAAAF4/FHdjr7dHw3g/s1600-h/Session5-switchb.png"&gt;&lt;img style="cursor: pointer; width: 291px; height: 353px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg1BQ4KCIZI/AAAAAAAAAF4/FHdjr7dHw3g/s400/Session5-switchb.png" alt="" id="BLOGGER_PHOTO_ID_5335992891712086418" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;1. Create a new database&lt;br /&gt;2. Edit a database&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;3. Delete a database&lt;br /&gt;4. Merge databases&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;5. Exit system&lt;br /&gt;Choose an option: 2&lt;br /&gt;Editing...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg1BeE_1D4I/AAAAAAAAAGA/YJfMWq3Gxx0/s1600-h/Session5-switch+-+1.png"&gt;&lt;img style="cursor: pointer; width: 291px; height: 128px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg1BeE_1D4I/AAAAAAAAAGA/YJfMWq3Gxx0/s400/Session5-switch+-+1.png" alt="" id="BLOGGER_PHOTO_ID_5335993118497247106" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We declare an integer variable &lt;span style="font-family:courier new;"&gt;choice&lt;/span&gt;. Then we display the options that user can choose and ask the user to input his/her choice. &lt;span style="font-family:courier new;"&gt;scanf()&lt;/span&gt; reads the input value and store it in variable &lt;span style="font-family:courier new;"&gt;choice&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg1Bn5bbbfI/AAAAAAAAAGI/Pks2pV0tH9g/s1600-h/Session5-switch+-+2.png"&gt;&lt;img style="cursor: pointer; width: 291px; height: 321px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg1Bn5bbbfI/AAAAAAAAAGI/Pks2pV0tH9g/s400/Session5-switch+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5335993287190474226" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next we have the &lt;span style="font-family:courier new;"&gt;switch&lt;/span&gt; statement that will select from the specified &lt;span style="font-family:courier new;"&gt;case&lt;/span&gt;s. A &lt;span style="font-family:courier new;"&gt;case&lt;/span&gt; is selected depending on the entered value of choice. Statement belong to the selected case will be executed and the break at the end of the case causes the program to jump to the statement following the switch block. In the case of user enters a value other than one (1) to five (5), default case will be executed displaying a message or invalid input.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-61-while-repetition-structure.html"&gt;while Loop&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-7423840492939880487?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/7423840492939880487/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-54-switch-selection-structure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/7423840492939880487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/7423840492939880487'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-54-switch-selection-structure.html' title='Tutorial 5.4: switch Selection Structure'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_264sc_gncA4/Sg1BC1xrkPI/AAAAAAAAAFo/nWK5HD3wlfA/s72-c/Session5-switch+structure.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-7565628741827299052</id><published>2009-05-14T13:56:00.004+08:00</published><updated>2009-07-13T12:08:59.485+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Selection Structure'/><category scheme='http://www.blogger.com/atom/ns#' term='Nested if'/><title type='text'>Tutorial 5.3: Nested if Selection Structure</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Nested &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; Statement&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;It is possible to have &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; within &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; statement. The &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; within an &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; is called nested &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt;. The flowchart illustrates the concept of nested if. Do take note that &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; can also be place within &lt;span style="font-family:courier new;"&gt;else&lt;/span&gt; statement.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sg1NkzAJFXI/AAAAAAAAAHQ/YghgUrUEXU8/s1600-h/Session5-nested+flowchart.png"&gt;&lt;img style="cursor: pointer; width: 238px; height: 400px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sg1NkzAJFXI/AAAAAAAAAHQ/YghgUrUEXU8/s400/Session5-nested+flowchart.png" alt="" id="BLOGGER_PHOTO_ID_5336006428065338738" border="0" /&gt;&lt;/a&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;Lets look at an example of nested &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg1AMCfd0CI/AAAAAAAAAFY/QksUcSDvqwc/s1600-h/Session5-nested.png"&gt;&lt;img style="cursor: pointer; width: 354px; height: 289px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg1AMCfd0CI/AAAAAAAAAFY/QksUcSDvqwc/s400/Session5-nested.png" alt="" id="BLOGGER_PHOTO_ID_5335991709075361826" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Enter a number between -10 and 10: 6&lt;br /&gt;6 is a positive number&lt;br /&gt;6 is an even number&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg1ARy-E6CI/AAAAAAAAAFg/coWqQoSa5UQ/s1600-h/Session5-nested+-+2.png"&gt;&lt;img style="cursor: pointer; width: 354px; height: 146px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg1ARy-E6CI/AAAAAAAAAFg/coWqQoSa5UQ/s400/Session5-nested+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5335991807988000802" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here we have &lt;span style="font-family:courier new;"&gt;if else&lt;/span&gt; selection structure within the &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; statement that tests whether the variable &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt; is an even or odd number. Notice that the nested &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; will only be checked if the condition of the &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; statement is true. The braces enclosing the nested &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; are necessary to make the nested &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; a part of &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; (first) statement.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-54-switch-selection-structure.html"&gt;&lt;span style="font-family:courier new;"&gt;switch&lt;/span&gt; Statement&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-7565628741827299052?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/7565628741827299052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-53-nested-if-selection.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/7565628741827299052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/7565628741827299052'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-53-nested-if-selection.html' title='Tutorial 5.3: Nested if Selection Structure'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_264sc_gncA4/Sg1NkzAJFXI/AAAAAAAAAHQ/YghgUrUEXU8/s72-c/Session5-nested+flowchart.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-5616309328308726703</id><published>2009-05-14T13:20:00.005+08:00</published><updated>2009-07-13T11:32:02.681+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='if else statement'/><category scheme='http://www.blogger.com/atom/ns#' term='Selection Structure'/><title type='text'>Tutorial 5.2: if else Selection Structure</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;Extending the &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; Statement&lt;/span&gt;&lt;br /&gt;Lets revise the last session, &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; statement allows a statement to be executed if the condition is true. If it is false the statement will be skipped. What if we want the program to execute certain statement if the condition is false. Remember the previous program's if statement.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg0_5dCVmmI/AAAAAAAAAFA/i7RhKqv4EcM/s1600-h/Session5-if+-+2.png"&gt;&lt;img style="cursor: pointer; width: 354px; height: 34px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg0_5dCVmmI/AAAAAAAAAFA/i7RhKqv4EcM/s400/Session5-if+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5335991389783431778" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The message will be displayed only when the condition is true. Lets make a few modification to the &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; selection structure.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg0_7YFSs6I/AAAAAAAAAFI/k-aIP8hHOQk/s1600-h/Session5-ifelse-2.png"&gt;&lt;img style="cursor: pointer; width: 354px; height: 66px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg0_7YFSs6I/AAAAAAAAAFI/k-aIP8hHOQk/s400/Session5-ifelse-2.png" alt="" id="BLOGGER_PHOTO_ID_5335991422813385634" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;As you can see we add &lt;span style="font-family:courier new;"&gt;else&lt;/span&gt; statment after the &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; statement. In the &lt;span style="font-family:courier new;"&gt;if else&lt;/span&gt; selection structure, the &lt;span style="font-family:courier new;"&gt;else&lt;/span&gt; statement will be executed when the condition is false. For example, if variable &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt; is less than 0, the first &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; will be skipped and the second &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; will be executed. The function of &lt;span style="font-family:courier new;"&gt;if els&lt;/span&gt;e selection is illustrated in the flowchart.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg1NdI86TrI/AAAAAAAAAHI/jt6SDSZXnu8/s1600-h/Session5-ifelse+flowchart.png"&gt;&lt;img style="cursor: pointer; width: 288px; height: 306px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg1NdI86TrI/AAAAAAAAAHI/jt6SDSZXnu8/s400/Session5-ifelse+flowchart.png" alt="" id="BLOGGER_PHOTO_ID_5336006296518414002" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The full program and the sample output are given below. The sample output shows two different outputs for positive number and negative number.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg1ACGPFrPI/AAAAAAAAAFQ/SDdGioEwsJo/s1600-h/Session5-ifelse.png"&gt;&lt;img style="cursor: pointer; width: 354px; height: 208px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg1ACGPFrPI/AAAAAAAAAFQ/SDdGioEwsJo/s400/Session5-ifelse.png" alt="" id="BLOGGER_PHOTO_ID_5335991538281721074" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Enter a number between -10 and 10: 6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;6 is a positive number&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Enter a number between -10 and 10: -2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;-2 is a negative number&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-53-nested-if-selection.html"&gt;Nested &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; Statement&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-5616309328308726703?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/5616309328308726703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-52-if-else-selection-structure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/5616309328308726703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/5616309328308726703'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-52-if-else-selection-structure.html' title='Tutorial 5.2: if else Selection Structure'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_264sc_gncA4/Sg0_5dCVmmI/AAAAAAAAAFA/i7RhKqv4EcM/s72-c/Session5-if+-+2.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-7297681760252847417</id><published>2009-05-14T12:01:00.004+08:00</published><updated>2009-07-13T11:29:56.935+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='if statement'/><category scheme='http://www.blogger.com/atom/ns#' term='Selection Structure'/><title type='text'>Tutorial 5.1: if Selection Structure</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Up until now, we have been writing a program that executes the statements one by one until the defined end. This type of program is called sequential structure. The functionality of this type of program is limited since it flows in single direction. Now we will be looking at one of the most powerful programming feature - the ability to change the flow of program execution. It is achieve by establishing the truth or falsity of an expression (condition). This type of program is called selection structure.&lt;br /&gt;&lt;br /&gt;Selection structure is extensively used in programming because it allows the program to decide an action based upon user's input or other processes. The application of selection structure can be seen at systems that have password checking such as ATM Machine, handphone and etc.. The system allows user access only if the user input password is the same as the corresponding password  stored in the system. In C, there are three types of selection structure can be implemented, namely if selection statement, if else selection statement and switch selection statement.&lt;br /&gt;&lt;br /&gt;Before we go further into the selection structure, you need to know the meaning of &lt;span style="color: rgb(255, 0, 0);"&gt;True &lt;/span&gt;and &lt;span style="color: rgb(255, 0, 0);"&gt;False &lt;/span&gt;in programming. An expression that evaluates to non-zero (1) is considered true expression while false expression evaluates to zero (0). Refer to &lt;a href="http://beginningcprogramming.blogspot.com/2009/05/operators.html"&gt;example&lt;/a&gt; of Tutorial 4&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; Selection Statement&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; is the primary tool of selection structure. &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; is used when we want a single or a group of statements to be executed if the condition is true. If the condition is false, the statement is skipped and program continues by executing the first statement after the if selection structure. The flowchart illustrates the function of if selection.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg1NQO07BGI/AAAAAAAAAHA/F-daXNmzv_s/s1600-h/Session5-if+flowchart.png"&gt;&lt;img style="cursor: pointer; width: 138px; height: 307px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg1NQO07BGI/AAAAAAAAAHA/F-daXNmzv_s/s400/Session5-if+flowchart.png" alt="" id="BLOGGER_PHOTO_ID_5336006074757219426" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;Lets look at an example that implement if selection structure. The program asks the user to input a number between -10 and 10. Then it message if the number is a positive number.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg0_Qd-U9yI/AAAAAAAAAEo/n1G6VcgxzCo/s1600-h/Session5-if.png"&gt;&lt;img style="cursor: pointer; width: 354px; height: 178px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg0_Qd-U9yI/AAAAAAAAAEo/n1G6VcgxzCo/s400/Session5-if.png" alt="" id="BLOGGER_PHOTO_ID_5335990685660411682" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Enter a nu&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;mbe&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;r between -&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;10 and 10: 6&lt;br /&gt;6 is a positive number&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg0_eDYTsQI/AAAAAAAAAEw/YKPDZKstwWo/s1600-h/Session5-if+-+1.png"&gt;&lt;img style="cursor: pointer; width: 354px; height: 48px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg0_eDYTsQI/AAAAAAAAAEw/YKPDZKstwWo/s400/Session5-if+-+1.png" alt="" id="BLOGGER_PHOTO_ID_5335990919039791362" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We declare a variable called &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt; and then we prompt the user to enter a number between -10 and 10. The &lt;span style="font-family:courier new;"&gt;scanf&lt;/span&gt; statement reads the user input and store it in variable &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg0_gbpA2iI/AAAAAAAAAE4/3SKWnoRrF_E/s1600-h/Session5-if+-+2.png"&gt;&lt;img style="cursor: pointer; width: 354px; height: 34px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg0_gbpA2iI/AAAAAAAAAE4/3SKWnoRrF_E/s400/Session5-if+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5335990959912049186" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; statement compare the value in &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt; with the value of 0. If &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt; is greater than 0, the &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; will be executed which displays a message and continue with the next part of the program. If it is not greater than 0, the &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; will be skipped.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Next: &lt;/span&gt;&lt;a href="http://begincprogram.blogspot.com/2009/05/tutorial-52-if-else-selection-structure.html"&gt;Extending the &lt;span style="font-family:courier new;"&gt;if&lt;/span&gt; Statement&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-7297681760252847417?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/7297681760252847417/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-51-if-selection-structure.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/7297681760252847417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/7297681760252847417'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/tutorial-51-if-selection-structure.html' title='Tutorial 5.1: if Selection Structure'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_264sc_gncA4/Sg1NQO07BGI/AAAAAAAAAHA/F-daXNmzv_s/s72-c/Session5-if+flowchart.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-4207242399579768700</id><published>2009-05-13T21:59:00.003+08:00</published><updated>2009-06-10T16:44:54.801+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Associativity'/><category scheme='http://www.blogger.com/atom/ns#' term='Arithmetic Operator'/><category scheme='http://www.blogger.com/atom/ns#' term='Relational Operator'/><category scheme='http://www.blogger.com/atom/ns#' term='Precedence'/><category scheme='http://www.blogger.com/atom/ns#' term='Logical Operator'/><category scheme='http://www.blogger.com/atom/ns#' term='Increment and Decrement Operator'/><title type='text'>Tutorial 4: Operators</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;Arithmetic Operators&lt;/span&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;br /&gt;&lt;/span&gt;Arithmetic operations can be performed in C programming language. There are five operators available in C which are &lt;span style="font-family:courier new;"&gt;+&lt;/span&gt; (addition), &lt;span style="font-family:courier new;"&gt;-&lt;/span&gt; (subtraction), &lt;span style="font-family:courier new;"&gt;*&lt;/span&gt; (multiplication), &lt;span style="font-family:courier new;"&gt;/&lt;/span&gt; (division) and &lt;span style="font-family:courier new;"&gt;%&lt;/span&gt; (modulus). &lt;span style="font-family:courier new;"&gt;+, -, *&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;/&lt;/span&gt; are self explained. &lt;span style="font-family:courier new;"&gt;%&lt;/span&gt; operator is to obtain the remainder of when we are dividing a number with a number. For example,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;x % y&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;produce the remainder when &lt;span style="font-family:courier new;"&gt;x&lt;/span&gt; is divided by &lt;span style="font-family:courier new;"&gt;y&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;The multiplication, division and modulus have higher precedence over the addition and subtraction. Its means &lt;span style="font-family:courier new;"&gt;/, *&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;%&lt;/span&gt; will be evaluated before &lt;span style="font-family:courier new;"&gt;+&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;-&lt;/span&gt; operators.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Relational and Logical Operators&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;There are six (6) relational operators which are                           &lt;span style="font-family:courier new;"&gt;&lt;&lt;/span&gt; (Less than),                     &lt;span style="font-family:courier new;"&gt;&gt;&lt;/span&gt; (Greater than),              &lt;span style="font-family:courier new;"&gt;&lt;=&lt;/span&gt; (Less or Equal to), &lt;span style="font-family:courier new;"&gt;&gt;=&lt;/span&gt; (Greater or Equal to), &lt;span style="font-family:courier new;"&gt;==&lt;/span&gt; (Equal to) and &lt;span style="font-family:courier new;"&gt;!=&lt;/span&gt; (Not equal to). Note that relational operators have lower precedence than arithmetic operators.&lt;br /&gt;&lt;br /&gt;There are two (2) logical operators which are &lt;span style="font-family:courier new;"&gt;||&lt;/span&gt; (OR) and &lt;span style="font-family:courier new;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; (AND). Expression consists of logical operators is evaluated left to right. The precedence of &lt;span style="font-family:courier new;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; is higher than &lt;span style="font-family:courier new;"&gt;||&lt;/span&gt; and logical operators have lower precedence than relational operators. There is a unary negation operator &lt;span style="font-family:courier new;"&gt;!&lt;/span&gt; that converts a zero (0) to one (1) and vice-verse.&lt;br /&gt;&lt;br /&gt;For example lets look at the following expression. Assume &lt;span style="font-family:courier new;"&gt;x = 2, y = 9&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;z = 3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;x &amp;gt; 5 || y &amp;lt; 7 &amp;amp;&amp;amp; z != 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Since relational operators have higher precedence, they will be evaluated first.&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;x &gt; 5&lt;/span&gt; returns False (0)&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;y &amp;lt; 7&lt;/span&gt; returns True (1)&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;z != 2&lt;/span&gt; returns True (1)&lt;br /&gt;&lt;br /&gt;Thus, the expression can be rewritten as&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;0 || 1 &amp;amp;&amp;amp; 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, &lt;span style="font-family:courier new;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; is evaluated then &lt;span style="font-family:courier new;"&gt;||&lt;/span&gt;. Expression 1 &lt;span style="font-family:courier new;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; 1 returns 1, then the expression becomes&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;0 || 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;which returns 1.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Increment and Decrement Operators&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;C provides two operators for incrementing and decrementing variables. If we have&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;++x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;the expression is adding x by 1. Similarly if we have&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;--x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;the expression is subtracting x by 1.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Postfix and Prefix&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Writing the increment or decrement operator in front of a variable is called prefix form. We may write the operator after a variable and this is called postfix form. Post-incrementing or pre-incrementing variable has the same effect if it is not used in an expression. Ultimately the value of the variable is added by 1. Post-incrementing and pre-incrementing must be considered when it is used in an expression. This is because for a variable that is post-incremented, the incrementing of the variable is performed &lt;span style="color: rgb(51, 102, 255);"&gt;after&lt;/span&gt; the variable is used while for pre-incrementing, the incrementing is performed &lt;span style="color: rgb(51, 102, 255);"&gt;before&lt;/span&gt; the variable is used. This is a bit confusing but lets look at an example to have better understanding. Assume i = 20 and j = 4 in the statement&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;sum = i - j++;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;sum&lt;/span&gt; will have the value of 16 since &lt;span style="font-family:courier new;"&gt;j&lt;/span&gt; is incremented after the expression is evaluated. After evaluation &lt;span style="font-family:courier new;"&gt;j&lt;/span&gt; will have the value of 5.&lt;br /&gt;&lt;br /&gt;Now consider the following statement.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;sum = i - ++j;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;sum&lt;/span&gt; will have the value of 15 since &lt;span style="font-family:courier new;"&gt;j&lt;/span&gt; is incremented before the expression is evaluated. After evaluation &lt;span style="font-family:courier new;"&gt;j&lt;/span&gt; will have the value of 5. Now you can see the different. Post-incrementing and pre-increment do can effect the result of an expression. Therefore we have to be careful when using with it in an expression.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 153);"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Summary of Operators Precedence and Associativity¹&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/SguWFZryZ3I/AAAAAAAAAA0/gAGy7WgDJ8U/s1600-h/Precedence+%26+Associativity.jpg"&gt;&lt;img style="cursor: pointer; width: 369px; height: 400px;" src="http://1.bp.blogspot.com/_264sc_gncA4/SguWFZryZ3I/AAAAAAAAAA0/gAGy7WgDJ8U/s400/Precedence+%26+Associativity.jpg" alt="" id="BLOGGER_PHOTO_ID_5335523203088541554" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-weight: bold;"&gt;¹(Kernighan &amp;amp; Ritchie) The Ansi C Programming Language&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-4207242399579768700?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/4207242399579768700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/operators.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/4207242399579768700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/4207242399579768700'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/operators.html' title='Tutorial 4: Operators'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_264sc_gncA4/SguWFZryZ3I/AAAAAAAAAA0/gAGy7WgDJ8U/s72-c/Precedence+%26+Associativity.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-5831887676713192806</id><published>2009-05-13T21:50:00.002+08:00</published><updated>2009-06-10T16:45:05.986+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='printf'/><category scheme='http://www.blogger.com/atom/ns#' term='I/O'/><category scheme='http://www.blogger.com/atom/ns#' term='scanf'/><title type='text'>Tutorial 3:  Output and Input</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;Outputting Information Using &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;printf is a standard library function which can be used to output information to the display screen. It function is to output whatever information contained between the parentheses. For example,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;printf("C program example\n");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The printf is used to print everything between the quotation marks on monitor screen. Notice that there is a ‘&lt;span style="font-family:courier new;"&gt;\n&lt;/span&gt;’ character at the end of the &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt; statement. This character is called newline escape sequence. The function of this escape sequence is to print a newline. There are more escape sequences available in C. We will be looking at the escape sequences later.&lt;br /&gt;&lt;br /&gt;The function &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; can also be used to print the value stored in a variable. For example,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;printf("%d\n", num);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt; has two arguments. "&lt;span style="font-family:courier new;"&gt;%d\n&lt;/span&gt;" and &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt;. The first argument consists of conversion specifier "&lt;span style="font-family:courier new;"&gt;%d&lt;/span&gt;" indicates that an integer is to be displayed on the monitor screen. The second argument contains the variable that stores the value to be printed which in this case variable &lt;span style="font-family:courier new;"&gt;num&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Inputting Information Using &lt;span style="font-family:courier new;"&gt;scanf&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;scanf &lt;/span&gt;is a standard library function which is used to input information from keyboard. It takes whatever entered from the keyboard and interprets it as specified by the conversion specifier and stores the result in a variable. The following is an example of &lt;span style="font-family:courier new;"&gt;scanf &lt;/span&gt;function statement.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;scanf("%d", &amp;amp;variable);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The first argument consists of conversion specifier "&lt;span style="font-family:courier new;"&gt;%d&lt;/span&gt;" indicates that an integer is to be read from the standard input which is usually the keyboard. The second argument is where we specify the variable to be used to store the input integer. Notice that the variable name starts with the &lt;span style="font-family:courier new;"&gt;&amp;amp;&lt;/span&gt; (ampersand)  character. The &lt;span style="font-family:courier new;"&gt;&amp;amp;&lt;/span&gt; is the address-of operator in C programming. It tells the &lt;span style="font-family:courier new;"&gt;scanf &lt;/span&gt;function the location (address) of the memory is stored in memory.&lt;br /&gt;&lt;br /&gt;Lets look at an example of I/O operations&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg6gEbwIWGI/AAAAAAAAAJI/LE68gk2yTCY/s1600-h/Session2-IO.png"&gt;&lt;img style="cursor: pointer; width: 256px; height: 193px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg6gEbwIWGI/AAAAAAAAAJI/LE68gk2yTCY/s400/Session2-IO.png" alt="" id="BLOGGER_PHOTO_ID_5336378606510168162" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Enter two numbers:&lt;br /&gt;5&lt;br /&gt;7&lt;br /&gt;v1 is 5&lt;br /&gt;v2 is 7&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg6g0FW4DjI/AAAAAAAAAJQ/AOq0-v69oU0/s1600-h/Session2-IO+-+1.png"&gt;&lt;img style="cursor: pointer; width: 256px; height: 16px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg6g0FW4DjI/AAAAAAAAAJQ/AOq0-v69oU0/s400/Session2-IO+-+1.png" alt="" id="BLOGGER_PHOTO_ID_5336379425132383794" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We begin with integer variables declaration namely &lt;span style=";font-family:courier new;font-size:85%;"  &gt;v1 &lt;/span&gt;and &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;v2&lt;/span&gt;&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sg6hEktRgJI/AAAAAAAAAJY/H7Nkc9vWA38/s1600-h/Session2-IO+-+2.png"&gt;&lt;img style="cursor: pointer; width: 256px; height: 16px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sg6hEktRgJI/AAAAAAAAAJY/H7Nkc9vWA38/s400/Session2-IO+-+2.png" alt="" id="BLOGGER_PHOTO_ID_5336379708425732242" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Then we display a prompt message asking user to input two numbers.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg6hYX6f5EI/AAAAAAAAAJg/bpzlUk6sgEg/s1600-h/Session2-IO+-+3.png"&gt;&lt;img style="cursor: pointer; width: 256px; height: 33px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg6hYX6f5EI/AAAAAAAAAJg/bpzlUk6sgEg/s400/Session2-IO+-+3.png" alt="" id="BLOGGER_PHOTO_ID_5336380048588923970" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;These statements read the user inputs from the keyboard and store the values in variable &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;v1 &lt;/span&gt;&lt;/span&gt;and &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;v2&lt;/span&gt;&lt;/span&gt;. In the sample output, the entered number are 5 and 7. So 5 is stored in v1 and 7 is stored in v2.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sg6iL0i9EPI/AAAAAAAAAJo/1z6_XRGU5Ck/s1600-h/Session2-IO+-+4.png"&gt;&lt;img style="cursor: pointer; width: 256px; height: 34px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sg6iL0i9EPI/AAAAAAAAAJo/1z6_XRGU5Ck/s400/Session2-IO+-+4.png" alt="" id="BLOGGER_PHOTO_ID_5336380932448129266" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The first argument of &lt;span style="font-family:courier new;"&gt;printf&lt;/span&gt; statement&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt; consists of string to be displayed and a conversion specifier. The second argument specifies the variable that stores the value to be printed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-5831887676713192806?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/5831887676713192806/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/session-3-outputting-and-inputting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/5831887676713192806'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/5831887676713192806'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/session-3-outputting-and-inputting.html' title='Tutorial 3:  Output and Input'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_264sc_gncA4/Sg6gEbwIWGI/AAAAAAAAAJI/LE68gk2yTCY/s72-c/Session2-IO.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-8755793535442949815</id><published>2009-05-13T21:44:00.005+08:00</published><updated>2009-06-10T16:45:31.436+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='double'/><category scheme='http://www.blogger.com/atom/ns#' term='char'/><category scheme='http://www.blogger.com/atom/ns#' term='float'/><category scheme='http://www.blogger.com/atom/ns#' term='int'/><category scheme='http://www.blogger.com/atom/ns#' term='Data Type'/><category scheme='http://www.blogger.com/atom/ns#' term='Variable'/><title type='text'>Tutorial 2: Variables and Data Types</title><content type='html'>Variable is a memory location that can store a value. The stored value can be retrieved or modified when necessary. Initialization of a variable means a value is given to the variable during its declaration. When a variable is declared, its name and data type are specified.&lt;br /&gt;&lt;br /&gt;A variable name can contain letters, digit and underscore (_). It cannot begins with a digit. C is case sensitive, therefore v and V are considered two different variable names. Its data type is given to specify what type of data can be stored in the variable.&lt;br /&gt;&lt;br /&gt;There are four basic data types in C programming language: &lt;span style="color: rgb(51, 102, 255);font-family:courier new;" &gt;int, float, double and char&lt;/span&gt;. Each data type has its own size. The size of a variable is the memory space allocated in the memory required to store its value.&lt;blockqoute&gt;&lt;/blockqoute&gt; The following example demonstrates on how to declare a variable for each data type.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sife7W2RyQI/AAAAAAAAAXI/-EfTku_1pRM/s1600-h/Session2-declarevar.png"&gt;&lt;img style="cursor: pointer; width: 237px; height: 148px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sife7W2RyQI/AAAAAAAAAXI/-EfTku_1pRM/s400/Session2-declarevar.png" alt="" id="BLOGGER_PHOTO_ID_5343484594225268994" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The statements declare four variables of types &lt;span style="font-family:courier new;"&gt;int&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;float&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;double&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;char&lt;/span&gt; with the name of &lt;span style="font-family:courier new;"&gt;num1&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;num2&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;num3&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;letter&lt;/span&gt;. Now that we have declared the variables, lets look at how to initialize them.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/SifgigVs5wI/AAAAAAAAAXY/Qw5himJqCA4/s1600-h/Session2-initializevar.png"&gt;&lt;img style="cursor: pointer; width: 185px; height: 239px;" src="http://4.bp.blogspot.com/_264sc_gncA4/SifgigVs5wI/AAAAAAAAAXY/Qw5himJqCA4/s400/Session2-initializevar.png" alt="" id="BLOGGER_PHOTO_ID_5343486366299514626" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We use '=' (assignment operator) to initialize the variables such as the value of &lt;span style="font-family:courier new;"&gt;5&lt;/span&gt; into variable &lt;span style="font-family:courier new;"&gt;num1&lt;/span&gt;. We could also perform the declaration and initialization on a single statement. This is demonstrated in the following program.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/SifiX4w9aJI/AAAAAAAAAXg/YcPvgTCjAY8/s1600-h/Session2-initialize_declarevar.png"&gt;&lt;img style="cursor: pointer; width: 222px; height: 186px;" src="http://2.bp.blogspot.com/_264sc_gncA4/SifiX4w9aJI/AAAAAAAAAXg/YcPvgTCjAY8/s400/Session2-initialize_declarevar.png" alt="" id="BLOGGER_PHOTO_ID_5343488382900988050" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-8755793535442949815?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/8755793535442949815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/session-2-variables-and-data-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/8755793535442949815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/8755793535442949815'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/session-2-variables-and-data-types.html' title='Tutorial 2: Variables and Data Types'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_264sc_gncA4/Sife7W2RyQI/AAAAAAAAAXI/-EfTku_1pRM/s72-c/Session2-declarevar.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-1832979691569478811</id><published>2009-05-13T21:28:00.003+08:00</published><updated>2009-06-19T20:59:41.802+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++ IDE'/><category scheme='http://www.blogger.com/atom/ns#' term='#define'/><category scheme='http://www.blogger.com/atom/ns#' term='Introduction'/><title type='text'>Tutorial 1: Introduction to C Programming</title><content type='html'>&lt;span style="color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;C was developed in 1972 by Dennis Ritchie based on a programming language called B (which is derived from BCPL language). It is one the most used programming language in software development area. At the beginning, C was designed and developed for the development of UNIX operating system. Today C has been widely used to develop many type of application software such as basic calculator, word processor, games, operating system etc.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;Getting Started - New to C Language?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Before we discuss C syntax in details, we look at the fundamental stages of C program development. Typically there are four development stages namely &lt;span style="color: rgb(51, 102, 255);"&gt;editing&lt;/span&gt;, &lt;span style="color: rgb(51, 102, 255);"&gt;pre-processing and compiling&lt;/span&gt;, &lt;span style="color: rgb(51, 102, 255);"&gt;linking&lt;/span&gt; and &lt;span style="color: rgb(51, 102, 255);"&gt;executing&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Editing&lt;/span&gt;&lt;br /&gt;Editing is the process of writing the C source code. Programmers write C source code using editor program. There are many editor program available for C. But two editors widely used on Linux platform are vi and emacs. On Windows platform, we can use Notepad as the editor program but most peoples use software package for C such as &lt;a href="http://www.codegear.com/products/cppbuilder"&gt;C++ Builder&lt;/a&gt;, &lt;a href="http://www.codeblocks.org/"&gt;Code::Blocks&lt;/a&gt;, &lt;a href="http://www.bloodshed.net/"&gt;Dev-C++&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/vstudio/express/default.aspx"&gt;Microsoft Visual Studio&lt;/a&gt; etc. that have integrated editor. These software provides complete programming environment for writing, managing, compiling, debugging and testing C source code. This is also known as Integrated Development Environment (IDE).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Pre-processing and Compiling&lt;/span&gt;&lt;br /&gt;A C source has to be translated into machine language code. Machine language is a language that computer can understand in the form of binary number. The process of code translation is called compiling. During compilation process, the compiler can detect any &lt;span style="color: rgb(51, 102, 255);"&gt;syntax error&lt;/span&gt; due to unrecognised program code as well as structural errors. The output of compilation process is an object code which is saved in a file called &lt;span style="color: rgb(51, 102, 255);"&gt;object file&lt;/span&gt;. In C, before a source code is compiled, there is a stage called pre-processing. During this stage, C pre-processor performs directives which are usually including header or other C files to be compiled and text substitution.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Linking&lt;/span&gt;&lt;br /&gt;Linking is a process of combining generated object files, add required codes from C standard library and produce an executable file. C standard library is collection of header files. Header files contain C source code that performs common operation such as input/output, mathematical operation and string handling.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Execution&lt;/span&gt;&lt;br /&gt;The execution stage is where you run the program to check whether it produce the desired output. This stage can be a testing stage where you check the output of your program. If it does not produces the suppose output, then you have made &lt;span style="color: rgb(51, 102, 255);"&gt;logic (semantic) error&lt;/span&gt; in your source code. Unlike syntax error, logic error won't be detected during compilation process. Therefore you have to find out the error's location by yourself.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;C Program Layout&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Basically, a C program consists of two sections:&lt;br /&gt;1. pre-processor directives&lt;br /&gt;2. main function&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg5YmatMPGI/AAAAAAAAAI4/cRG4z8fS7Xo/s1600-h/Session1-program+sections.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 89px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg5YmatMPGI/AAAAAAAAAI4/cRG4z8fS7Xo/s400/Session1-program+sections.png" alt="" id="BLOGGER_PHOTO_ID_5336300025507757154" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The pre-processor section is the place where we specify what compiler should do before compiling the source code. Usually we would specify the included header file which will be used in our program. A header file keeps all the information about functions available in standard C library. All pre-processor directives begins with the &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;#&lt;/span&gt;&lt;/span&gt; symbol. The second section begins with the function &lt;span style="font-family:courier new;"&gt;main()&lt;/span&gt; definition. The function &lt;span style="font-family:courier new;"&gt;main() &lt;/span&gt;is where the program starts its execution. Thus function &lt;span style="font-family:courier new;"&gt;main()&lt;/span&gt; must present in any C program.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span&gt;An Example of C Program&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;We begin by programming a very simple C program. Write the following program using your editor program. When you finish writing it, compile it and execute the program. You will get a text message displayed on your monitor screen. The program's output is given at the sample output section. Don't worry if what you type does not make sense. I'll explain everything later.&lt;br /&gt;&lt;blockqoute&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockqoute&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sg08Ilj6QCI/AAAAAAAAAEg/SJOEjgkDc4c/s1600-h/Session1-intro.png"&gt;&lt;img style="cursor: pointer; width: 242px; height: 147px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sg08Ilj6QCI/AAAAAAAAAEg/SJOEjgkDc4c/s400/Session1-intro.png" alt="" id="BLOGGER_PHOTO_ID_5335987251723255842" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;blockqoute&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sample output:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;C program example&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;br /&gt;&lt;/span&gt;&lt;/blockqoute&gt;&lt;br /&gt;The first line of the program is&lt;blockqoute&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockqoute&gt;&lt;blockqoute&gt;&lt;/blockqoute&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg4yYo880NI/AAAAAAAAAHo/9EjUXYoLqY4/s1600-h/Session1-intro+-+comment1.png"&gt;&lt;img style="cursor: pointer; width: 242px; height: 19px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg4yYo880NI/AAAAAAAAAHo/9EjUXYoLqY4/s400/Session1-intro+-+comment1.png" alt="" id="BLOGGER_PHOTO_ID_5336258007371927762" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This line is not actually part of the program. It is simply a comment and it is included to provide information on what the program does. A comment begins with &lt;span style=";font-family:courier new;font-size:85%;"  &gt;/*&lt;/span&gt; and end with &lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;*/&lt;/span&gt;&lt;/span&gt;. It is a good habit to include comments in every part of your program especially when you are writing a big program/project. It will keep you inform what are the code actually doing since you may not always remember what they do.&lt;br /&gt;&lt;br /&gt;Then we have the next line which is&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg40SIxJSxI/AAAAAAAAAHw/-LKBAV00Ins/s1600-h/Session1-intro+-+include.png"&gt;&lt;img style="cursor: pointer; width: 241px; height: 16px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg40SIxJSxI/AAAAAAAAAHw/-LKBAV00Ins/s400/Session1-intro+-+include.png" alt="" id="BLOGGER_PHOTO_ID_5336260094676519698" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This is also not part of the program, but it is a very important line in C program. In fact, if this line is omitted, the program won't actually works. The symbol # indicates that this is a pre-processor directive. Remember about header file that I mentioned during compilation process. This line is a directive to the compiler to include &lt;span style="font-family:courier new;"&gt;stdio.h&lt;/span&gt; header file in our program.&lt;span style="font-family:courier new;"&gt; stdio.h&lt;/span&gt; contains information on input/output routines which will be needed during compilation process. In this case we are using the &lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; function from &lt;span style="font-family:courier new;"&gt;stdio.h&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;The next line is&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg43eNQdNsI/AAAAAAAAAH4/gn8A_UM2-oA/s1600-h/Session1-intro+-+comment2.png"&gt;&lt;img style="cursor: pointer; width: 242px; height: 16px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg43eNQdNsI/AAAAAAAAAH4/gn8A_UM2-oA/s400/Session1-intro+-+comment2.png" alt="" id="BLOGGER_PHOTO_ID_5336263600574904002" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This is also another comment line.&lt;br /&gt;&lt;br /&gt;Then we have the main function section.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg44B1tXkuI/AAAAAAAAAIA/NLSpODp-giA/s1600-h/Session1-intro+-+main+function.png"&gt;&lt;img style="cursor: pointer; width: 242px; height: 82px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg44B1tXkuI/AAAAAAAAAIA/NLSpODp-giA/s400/Session1-intro+-+main+function.png" alt="" id="BLOGGER_PHOTO_ID_5336264212729008866" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The main function has only two (2) statements. The first is printf() statement and the second is return statement. I'll explain both statements in details later.&lt;br /&gt;&lt;br /&gt;Now we look at the first line of function &lt;span style="font-family:courier new;"&gt;main() &lt;/span&gt;definition.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg45OYWcNsI/AAAAAAAAAII/0kGMO-YSJx4/s1600-h/Session1-intro+-+main+definition.png"&gt;&lt;img style="cursor: pointer; width: 242px; height: 17px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg45OYWcNsI/AAAAAAAAAII/0kGMO-YSJx4/s400/Session1-intro+-+main+definition.png" alt="" id="BLOGGER_PHOTO_ID_5336265527698142914" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This defines the start of the function&lt;span style="font-family:courier new;"&gt; main()&lt;/span&gt;. Function &lt;span style="font-family:courier new;"&gt;main()&lt;/span&gt; has the keyword &lt;span style="font-family:courier new;"&gt;int&lt;/span&gt; signifies what type of value will be returned by the function. In this case the function &lt;span style="font-family:courier new;"&gt;main()&lt;/span&gt; will return an integer value. There parentheses following the main. This is the place where we specify information to be transferred to function main(). However, in this example we don't transfer any information.&lt;br /&gt;&lt;br /&gt;Then we have&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg5L3_BjEuI/AAAAAAAAAIY/p71OwG4soPI/s1600-h/Session1-intro+-+braces.png"&gt;&lt;img style="cursor: pointer; width: 212px; height: 66px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg5L3_BjEuI/AAAAAAAAAIY/p71OwG4soPI/s400/Session1-intro+-+braces.png" alt="" id="BLOGGER_PHOTO_ID_5336286033663431394" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The open brace specifies the start of the function whilehe close brace specifies the end of the function. The portion within the braces is called block or body. Within the block is where we write the statements that defines what our program does.&lt;br /&gt;&lt;br /&gt;Now lets look at the first statement.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sg5Mk0LuyJI/AAAAAAAAAIg/Wr0f8MkajeQ/s1600-h/Session1-intro+-+printf.png"&gt;&lt;img style="cursor: pointer; width: 242px; height: 18px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sg5Mk0LuyJI/AAAAAAAAAIg/Wr0f8MkajeQ/s400/Session1-intro+-+printf.png" alt="" id="BLOGGER_PHOTO_ID_5336286803847465106" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;printf()&lt;/span&gt; function instructs the computer to display characters or a string enclosed by the qoutation marks on the monitor screen. A &lt;span style="color: rgb(51, 102, 255);"&gt;string&lt;/span&gt; is a combination of numerous characters. Items enclosed by the parentheses are called &lt;span style="color: rgb(51, 102, 255);"&gt;arguments&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;The last statement in this program is&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sg5MqVzltxI/AAAAAAAAAIo/C4169kEX368/s1600-h/Session1-intro+-+return.png"&gt;&lt;img style="cursor: pointer; width: 242px; height: 16px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sg5MqVzltxI/AAAAAAAAAIo/C4169kEX368/s400/Session1-intro+-+return.png" alt="" id="BLOGGER_PHOTO_ID_5336286898772358930" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;At the end of function &lt;span style="font-family:courier new;"&gt;main()&lt;/span&gt; we have to include &lt;span style="font-family:courier new;"&gt;return 0&lt;/span&gt; statement because function main is defined to return a value of integer type. This statement also indicates that the program has terminated successfully.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Symbolic Constant&lt;span style="font-family:courier new;"&gt; - #define&lt;/span&gt; Directive&lt;/span&gt;&lt;br /&gt;I would like to discuss another pre-processor directive that is usually used in C programming. &lt;span style="font-family:courier new;"&gt;#define&lt;/span&gt; directive is used to define a symbol (name) that represents a constant value. Basically &lt;span style="font-family:courier new;"&gt;#define&lt;/span&gt; directive acts as a constant converter. It causes the compiler to go through all the program's codes and whenever it encounters the defined symbol, it will substitute the symbol with the specified value.  For example,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;#define PI 3.14159&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int main() {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Symbol &lt;span style="font-family:courier new;"&gt;PI&lt;/span&gt; is defined and it represents the value of &lt;span style="font-family:courier new;"&gt;3.14159&lt;/span&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-1832979691569478811?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/1832979691569478811/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/introduction-to-c-language-with.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1832979691569478811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1832979691569478811'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/introduction-to-c-language-with.html' title='Tutorial 1: Introduction to C Programming'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_264sc_gncA4/Sg5YmatMPGI/AAAAAAAAAI4/cRG4z8fS7Xo/s72-c/Session1-program+sections.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-1286545978091058341</id><published>2009-05-12T19:08:00.000+08:00</published><updated>2009-05-28T19:14:54.003+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Computer-aided Learning Multiplication Problem&apos;s Source Code'/><title type='text'>Computer-aided Learning Multiplication Problem's Source Code</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sh5wyaL6hTI/AAAAAAAAAT0/7ibrJuuM59A/s1600-h/Session7-project+-+direct.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 89px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sh5wyaL6hTI/AAAAAAAAAT0/7ibrJuuM59A/s400/Session7-project+-+direct.png" alt="" id="BLOGGER_PHOTO_ID_5340830219433051442" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sh5xhV7_6ZI/AAAAAAAAAU0/4Cd-rdUIeL0/s1600-h/Session7-project+-+globalvar.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 59px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sh5xhV7_6ZI/AAAAAAAAAU0/4Cd-rdUIeL0/s400/Session7-project+-+globalvar.png" alt="" id="BLOGGER_PHOTO_ID_5340831025746405778" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sh5xlrGuFVI/AAAAAAAAAU8/QE-5LnFisnk/s1600-h/Session7-project+-+funcprototype.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 89px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sh5xlrGuFVI/AAAAAAAAAU8/QE-5LnFisnk/s400/Session7-project+-+funcprototype.png" alt="" id="BLOGGER_PHOTO_ID_5340831100147995986" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sh5w7SVHrGI/AAAAAAAAAT8/8YpcwKlni7o/s1600-h/Session7-project+-+main.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 325px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sh5w7SVHrGI/AAAAAAAAAT8/8YpcwKlni7o/s400/Session7-project+-+main.png" alt="" id="BLOGGER_PHOTO_ID_5340830371943001186" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sh5xNi_aBEI/AAAAAAAAAUE/bUPukDFs0vk/s1600-h/Session7-project+-+userinstruct.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 88px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sh5xNi_aBEI/AAAAAAAAAUE/bUPukDFs0vk/s400/Session7-project+-+userinstruct.png" alt="" id="BLOGGER_PHOTO_ID_5340830685652976706" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sh5xRB9N4TI/AAAAAAAAAUM/BinYMpDW0vY/s1600-h/Session7-project+-+genereate.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 58px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sh5xRB9N4TI/AAAAAAAAAUM/BinYMpDW0vY/s400/Session7-project+-+genereate.png" alt="" id="BLOGGER_PHOTO_ID_5340830745504899378" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sh5xUtyfMbI/AAAAAAAAAUU/N0IeiQxn2RM/s1600-h/Session7-project+-+printquestion.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 205px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sh5xUtyfMbI/AAAAAAAAAUU/N0IeiQxn2RM/s400/Session7-project+-+printquestion.png" alt="" id="BLOGGER_PHOTO_ID_5340830808810664370" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sh5xXm71WmI/AAAAAAAAAUc/rDG-JjSjTOU/s1600-h/Session7-project+-+inputans.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 309px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sh5xXm71WmI/AAAAAAAAAUc/rDG-JjSjTOU/s400/Session7-project+-+inputans.png" alt="" id="BLOGGER_PHOTO_ID_5340830858510424674" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sh5xbOSar1I/AAAAAAAAAUk/14tkEZDkL8c/s1600-h/Session7-project+-+adjustdiff.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 177px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sh5xbOSar1I/AAAAAAAAAUk/14tkEZDkL8c/s400/Session7-project+-+adjustdiff.png" alt="" id="BLOGGER_PHOTO_ID_5340830920613736274" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_264sc_gncA4/Sh5xeITJ9iI/AAAAAAAAAUs/5IsNAPGX9kw/s1600-h/Session7-project+-+printresult.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 88px;" src="http://2.bp.blogspot.com/_264sc_gncA4/Sh5xeITJ9iI/AAAAAAAAAUs/5IsNAPGX9kw/s400/Session7-project+-+printresult.png" alt="" id="BLOGGER_PHOTO_ID_5340830970545829410" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-1286545978091058341?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/1286545978091058341/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/computer-aided-learning-multiplication.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1286545978091058341'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/1286545978091058341'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/computer-aided-learning-multiplication.html' title='Computer-aided Learning Multiplication Problem&apos;s Source Code'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_264sc_gncA4/Sh5wyaL6hTI/AAAAAAAAAT0/7ibrJuuM59A/s72-c/Session7-project+-+direct.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7304028535821151454.post-5106962725261585186</id><published>2009-05-12T18:53:00.000+08:00</published><updated>2009-05-28T19:08:22.249+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Electricity Bill Problem Source Code'/><title type='text'>Electricity Bill Problem's Source Code</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_264sc_gncA4/Sh5v81e53GI/AAAAAAAAATM/ZHNIgSZ_ySQ/s1600-h/Session5-project+-+direct.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 62px;" src="http://1.bp.blogspot.com/_264sc_gncA4/Sh5v81e53GI/AAAAAAAAATM/ZHNIgSZ_ySQ/s400/Session5-project+-+direct.png" alt="" id="BLOGGER_PHOTO_ID_5340829299047521378" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sh5wBKcWHqI/AAAAAAAAATU/l-gKrEu03l8/s1600-h/Session5-project+-+declare.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 87px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sh5wBKcWHqI/AAAAAAAAATU/l-gKrEu03l8/s400/Session5-project+-+declare.png" alt="" id="BLOGGER_PHOTO_ID_5340829373393411746" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_264sc_gncA4/Sh5wHviR4_I/AAAAAAAAATc/EEH6MT_RtQ4/s1600-h/Session5-project+-+userinstruct.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 149px;" src="http://4.bp.blogspot.com/_264sc_gncA4/Sh5wHviR4_I/AAAAAAAAATc/EEH6MT_RtQ4/s400/Session5-project+-+userinstruct.png" alt="" id="BLOGGER_PHOTO_ID_5340829486429627378" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sh5wMNpSvmI/AAAAAAAAATk/Akdueo9dtZ0/s1600-h/Session5-project+-+computes.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 137px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sh5wMNpSvmI/AAAAAAAAATk/Akdueo9dtZ0/s400/Session5-project+-+computes.png" alt="" id="BLOGGER_PHOTO_ID_5340829563231583842" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_264sc_gncA4/Sh5wPF6-XcI/AAAAAAAAATs/Z3aLcMiK7jg/s1600-h/Session5-project+-+display.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 74px;" src="http://3.bp.blogspot.com/_264sc_gncA4/Sh5wPF6-XcI/AAAAAAAAATs/Z3aLcMiK7jg/s400/Session5-project+-+display.png" alt="" id="BLOGGER_PHOTO_ID_5340829612697869762" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7304028535821151454-5106962725261585186?l=begincprogram.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://begincprogram.blogspot.com/feeds/5106962725261585186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://begincprogram.blogspot.com/2009/05/electricity-bill-problems-source-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/5106962725261585186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7304028535821151454/posts/default/5106962725261585186'/><link rel='alternate' type='text/html' href='http://begincprogram.blogspot.com/2009/05/electricity-bill-problems-source-code.html' title='Electricity Bill Problem&apos;s Source Code'/><author><name>Halim Noor</name><uri>http://www.blogger.com/profile/11756350390122867086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_264sc_gncA4/Sh5v81e53GI/AAAAAAAAATM/ZHNIgSZ_ySQ/s72-c/Session5-project+-+direct.png' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
