<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-1%3Asbha077</id>
	<title>SE250:lab-1:sbha077 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-1%3Asbha077"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-1:sbha077&amp;action=history"/>
	<updated>2026-07-22T02:45:13Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-1:sbha077&amp;diff=4498&amp;oldid=prev</id>
		<title>Mark: 17 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-1:sbha077&amp;diff=4498&amp;oldid=prev"/>
		<updated>2008-11-03T05:18:45Z</updated>

		<summary type="html">&lt;p&gt;17 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Lab 1 Report ==&lt;br /&gt;
&lt;br /&gt;
=== What was done ===&lt;br /&gt;
&lt;br /&gt;
Not having done C for a few months I decided to use my my old Enggen 131 book and with the help of my mates the net, I finally managed to figure out what had to be done and what codes to use properly. Then, the clock() function. We&amp;#039;ve never used that before (atleast I haven&amp;#039;t anyway) - used GOOGLE for it and figured out how to use that function. In the end I faced a couple of problems that needed addressing but were debugged eventually.&lt;br /&gt;
&lt;br /&gt;
I also asked for a little bit of help from the lecturer as to why I was getting 0.000000 as my result. He suggested using a larger number instead as the pcs are really quick in doing the intended calculations.&lt;br /&gt;
&lt;br /&gt;
=== Problems faced ===&lt;br /&gt;
&lt;br /&gt;
1. I had made all the variables used in the code &amp;quot;local&amp;quot;. That resulted errors of &amp;quot;uninitialised local variable x&amp;quot; (etc.)&lt;br /&gt;
&lt;br /&gt;
Wrong way:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;time.h&amp;gt;&lt;br /&gt;
 clock_t start, stop;&lt;br /&gt;
 int main ()&lt;br /&gt;
 {&lt;br /&gt;
 int x;&lt;br /&gt;
 double z;&lt;br /&gt;
 float d;&lt;br /&gt;
 double elapsed;&lt;br /&gt;
&lt;br /&gt;
Right way:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;time.h&amp;gt;&lt;br /&gt;
 int x;&lt;br /&gt;
 double z;&lt;br /&gt;
 float d;&lt;br /&gt;
 clock_t start, stop;&lt;br /&gt;
 double elapsed;&lt;br /&gt;
 int main ()&lt;br /&gt;
 {&lt;br /&gt;
&lt;br /&gt;
2. I forgot to add the &amp;quot;/ CLOCKS_PER_SEC&amp;quot; bit during the total time calculation part which resulted in me not getting an answer in the first place.&lt;br /&gt;
   &lt;br /&gt;
   elapsed = ((double) (stop - start)) &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;/ CLOCKS_PER_SEC&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
3. I used the wrong syntax for the FOR loop&lt;br /&gt;
&lt;br /&gt;
Wrong way:&lt;br /&gt;
&lt;br /&gt;
 int x;&lt;br /&gt;
 x = 0;&lt;br /&gt;
      for x &amp;lt; 10;&lt;br /&gt;
      /* code */&lt;br /&gt;
&lt;br /&gt;
Right way:&lt;br /&gt;
&lt;br /&gt;
 for (x=0; x&amp;lt;5000; x++);&lt;br /&gt;
&lt;br /&gt;
=== Code ===&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;time.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 int x;&lt;br /&gt;
 double z;&lt;br /&gt;
 float d;&lt;br /&gt;
 clock_t start, stop;&lt;br /&gt;
 double elapsed;&lt;br /&gt;
 &lt;br /&gt;
 int main ()&lt;br /&gt;
 &lt;br /&gt;
 {&lt;br /&gt;
 &lt;br /&gt;
 start = clock();&lt;br /&gt;
 for (x=0; (x&amp;lt;100000000); x++); {&lt;br /&gt;
 z=z+z;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 stop = clock();&lt;br /&gt;
 elapsed = ((double) (stop - start)) / CLOCKS_PER_SE&lt;br /&gt;
 printf(&amp;quot;\nThe time taken for addition = %lf seconds\n&amp;quot;,elapsed);&lt;br /&gt;
 &lt;br /&gt;
 start = clock();&lt;br /&gt;
 for (x=0; (x&amp;lt;100000000); x++); {&lt;br /&gt;
 d=d+d;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 stop = clock();&lt;br /&gt;
 elapsed = ((double) (stop - start)) / CLOCKS_PER_SEC;&lt;br /&gt;
 printf(&amp;quot;\nThe time taken for addition = %lf seconds\n&amp;quot;,elapsed);&lt;br /&gt;
 return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
The values for x &amp;lt; 100000000:&lt;br /&gt;
&lt;br /&gt;
 The time taken for addition = 0.375000 seconds&lt;br /&gt;
&lt;br /&gt;
The values for x &amp;lt; 1000000000:&lt;br /&gt;
&lt;br /&gt;
 The time taken for addition = 3.843000 seconds&lt;br /&gt;
&lt;br /&gt;
=== Suggestions ===&lt;br /&gt;
&lt;br /&gt;
1. It&amp;#039;s a good idea to GOOGLE things out that you are not clear about.&lt;br /&gt;
&lt;br /&gt;
2. Use other programs like Visual Studio / Visual Studio Command Prompt to check your results and debug your program (its a bit easier).&lt;br /&gt;
&lt;br /&gt;
3. Never hestitate to ask anyone for help!&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>