103 lines
7.8 KiB
HTML
103 lines
7.8 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<title>Pyramid of Numbers: Pyramid of Numbers</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javaScript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body onload='searchBox.OnSelectItem(0);'>
|
|
<!-- Generated by Doxygen 1.7.0 -->
|
|
<script type="text/javascript"><!--
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
--></script>
|
|
<div class="navigation" id="top">
|
|
<div class="tabs">
|
|
<ul class="tablist">
|
|
<li class="current"><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li id="searchli">
|
|
<div id="MSearchBox" class="MSearchBoxInactive">
|
|
<span class="left">
|
|
<img id="MSearchSelect" src="search/mag_sel.png"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
alt=""/>
|
|
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
|
onfocus="searchBox.OnSearchFieldFocus(true)"
|
|
onblur="searchBox.OnSearchFieldFocus(false)"
|
|
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
|
</span><span class="right">
|
|
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
|
</span>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<h1>Pyramid of Numbers </h1> </div>
|
|
</div>
|
|
<div class="contents">
|
|
<dl class="author"><dt><b>Author:</b></dt><dd>Peter Bauer</dd></dl>
|
|
<h2><a class="anchor" id="intro"></a>
|
|
Introduction</h2>
|
|
<p>This weeks assignment deals with an old fashioned primary school problem. Most of you will know the "Turmrechnen" as a pain of your former school days. How it works is shown in the following example </p>
|
|
<pre>
|
|
Pyramid of Numbers</pre><pre>Please enter a number: 3453454359654646756757434
|
|
3453454359654646756757434 * 2 = 6906908719309293513514868
|
|
6906908719309293513514868 * 3 = 20720726157927880540544604
|
|
20720726157927880540544604 * 4 = 82882904631711522162178416
|
|
82882904631711522162178416 * 5 = 414414523158557610810892080
|
|
414414523158557610810892080 * 6 = 2486487138951345664865352480
|
|
2486487138951345664865352480 * 7 = 17405409972659419654057467360
|
|
17405409972659419654057467360 * 8 = 139243279781275357232459738880
|
|
139243279781275357232459738880 * 9 = 1253189518031478215092137649920
|
|
1253189518031478215092137649920 / 2 = 626594759015739107546068824960
|
|
626594759015739107546068824960 / 3 = 208864919671913035848689608320
|
|
208864919671913035848689608320 / 4 = 52216229917978258962172402080
|
|
52216229917978258962172402080 / 5 = 10443245983595651792434480416
|
|
10443245983595651792434480416 / 6 = 1740540997265941965405746736
|
|
1740540997265941965405746736 / 7 = 248648713895134566486535248
|
|
248648713895134566486535248 / 8 = 31081089236891820810816906
|
|
31081089236891820810816906 / 9 = 3453454359654646756757434</pre><pre></pre><p> To see more about it's internal structure browse through this documentation. A good starting point is, of course, the function <a class="el" href="pyramid__of__numbers_8c.html#a0ddf1224851353fc92bfbff6f499fa97">main()</a> and, furthermore, the struct <a class="el" href="struct_big_int.html">BigInt</a>.</p>
|
|
<p>When browsing through this documentation you might stumble over the keyword const in the argument list of several functions. This shows you that the argument must not be altered by the function, i.e., you may be sure that, even if a pointer is passed to the function the content of the argument is not changed in the function.</p>
|
|
<h2><a class="anchor" id="reading"></a>
|
|
Reading a big number</h2>
|
|
<p>We have to read in the number via a string. Check, whether the entered number does exceed the maximum length of MAX_DIGITS. In this case print an error message and leave the program with error code -1.</p>
|
|
<h2><a class="anchor" id="convert"></a>
|
|
Converting to a BigInt</h2>
|
|
<p>The string has than to be converted into a <a class="el" href="struct_big_int.html">BigInt</a>. Implement a function <a class="el" href="pyramid__of__numbers_8c.html#a2e54fded1d9a2c96d974dbc649ddaf45">strtobig_int()</a> as specified. The conversion of one single character c containing a digit to an int can be done via c - '0'. Also think of the correct way to fill the array. Is for the number 123456 the array element a[0] == 1 or is a[0] == 6? Finally do not forget to set BigInt.digits to the right value. After calling <a class="el" href="pyramid__of__numbers_8c.html#a2e54fded1d9a2c96d974dbc649ddaf45">strtobig_int()</a> check whether the function was able to convert the entire string. If not an invalid character occured in your string and the program should give an error message and should return with error code -2.</p>
|
|
<h2><a class="anchor" id="print"></a>
|
|
Printing a BigInt</h2>
|
|
<p>Should be straight forward.</p>
|
|
<h2><a class="anchor" id="calc"></a>
|
|
Multiply and Divide BigInts</h2>
|
|
<p>Do a few multiplications and division by hand (yes as you learned this in primary school :-)). Write down the tiny steps and transform these then into C source code. Keep stuck to the interface <a class="el" href="pyramid__of__numbers_8c.html#a98526606783facc829f03ee93d25a6ec">multiply()</a> and <a class="el" href="pyramid__of__numbers_8c.html#a83c208b490dc545cc8eaafe48a52b2ad">divide()</a> as given in this documentation. An Engish word you might need for naming a variable: "Uebertrag": carry</p>
|
|
<h2><a class="anchor" id="copy"></a>
|
|
Copying a BigInt</h2>
|
|
<p>Take care that simply assigning a <a class="el" href="struct_big_int.html">BigInt</a> from one variable to another will fail, because the array <a class="el" href="struct_big_int.html#a240e5ac8f50d6e79a604470d57b966c7">BigInt.the_int</a> won't be copied but only its pointer. Therefore, you have to write a function <a class="el" href="pyramid__of__numbers_8c.html#afc0bd0ac07f86448f1637a09d0d314bf">copy_big_int()</a>, which copies the array element by element. </p>
|
|
</div>
|
|
<!--- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Defines</a></div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<hr class="footer"/><address class="footer"><small>Generated on Thu Oct 5 2017 01:06:43 for Pyramid of Numbers by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.0 </small></address>
|
|
</body>
|
|
</html>
|