<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'is this codee alright ?' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'is this codee alright ?' posted on the 'C and C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 12:44:54 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 12:44:54 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>is this codee alright ?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/353722/353722/is-this-codee-alright-/</link>
      <description>#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main ()&lt;br /&gt;
{&lt;br /&gt;
	clrscr();&lt;br /&gt;
	float a=1;int p;float b;&lt;br /&gt;
	printf("Enter the value as format(power,base):");&lt;br /&gt;
	scanf("%f,%d",&amp;amp;b,&amp;amp;p);&lt;br /&gt;
	for (;p!=0;p--)&lt;br /&gt;
	a*=b;&lt;br /&gt;
	printf("\nAnswer=%g",a);&lt;br /&gt;
	getch();&lt;br /&gt;
}&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/353722/353722/is-this-codee-alright-/</guid>
      <pubDate>Fri, 09 Feb 2007 04:48:34 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: is this codee alright ?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/353722/353725/re-is-this-codee-alright-/#353725</link>
      <description>&lt;pre class="sourcecode"&gt;
: #include&amp;lt;stdio.h&amp;gt;
: #include&amp;lt;conio.h&amp;gt;
: 
: void main ()
: {
: 	clrscr();
: 	float a=1;int p;float b;
: 	printf("Enter the value as format(power,base):");
: 	scanf("%f,%d",&amp;amp;b,&amp;amp;p);
: 	for (;p!=0;p--)
: 	a*=b;
: 	printf("\nAnswer=%g",a);
: 	getch();
: }
: &lt;/pre&gt;&lt;br /&gt;
&lt;span style="color: Blue;"&gt;If it runs and gives the correct result - then it is fine.&lt;/span&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/353722/353725/re-is-this-codee-alright-/#353725</guid>
      <pubDate>Fri, 09 Feb 2007 05:16:57 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: is this codee alright ?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/353722/353727/re-is-this-codee-alright-/#353727</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by chenfeng7 at  2007-2-9 6:50:24&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by chenfeng7 at  2007-2-9 5:58:47&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by chenfeng7 at  2007-2-9 5:43:17&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by chenfeng7 at  2007-2-9 5:36:55&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by chenfeng7 at  2007-2-9 5:36:9&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: : #include&amp;lt;stdio.h&amp;gt;
: : #include&amp;lt;conio.h&amp;gt;
: : 
: : void main ()
: : {
: : 	clrscr();
: : 	float a=1;int p;float b;
: : 	printf("Enter the value as format(power,base):");
: : 	scanf("%f,%d",&amp;amp;b,&amp;amp;p);
: : 	for (;p!=0;p--)
: : 	a*=b;
: : 	printf("\nAnswer=%g",a);
: : 	getch();
: : }
: : &lt;/pre&gt;&lt;br /&gt;
: &lt;span style="color: Blue;"&gt;If it runs and gives the correct result - then it is fine.&lt;/span&gt;&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
**************************************************
********************&lt;br /&gt;
&lt;br /&gt;
I think it will not give the correct result (or am I the one who is mistaken?). Based from my understanding, the programmer wants to solve for &lt;span style="color: Blue;"&gt;base raised to power&lt;/span&gt;. The above code, however, computes for &lt;span style="color: Red;"&gt;power raised to base&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
If I am right, the "red" in the ff code snippet must be changed to "green":&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
/* solution 1 */
scanf(&lt;span style="color: Red;"&gt;"%f,%d",&amp;amp;b,&amp;amp;p&lt;/span&gt;);
scanf(&lt;span style="color: Green;"&gt;"%d,%f",&amp;amp;p,&amp;amp;b&lt;/span&gt;);

/* or solution 2 */
printf("Enter the value as format(&lt;span style="color: Red;"&gt;power,base&lt;/span&gt;):");
printf("Enter the value as format(&lt;span style="color: Green;"&gt;base,power&lt;/span&gt;):");

/* Note: &lt;strong&gt;Either&lt;/strong&gt; you do solution 1 or solution 2. &lt;strong&gt;Do not&lt;/strong&gt; do them both. */&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Correct me if I am wrong (grammatical errors too) but I think there is a &lt;span style="color: Red;"&gt;logic error&lt;/span&gt; in this program. One more thing, variable declarations should come before any other statement. In other words, do this:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;float a=1; int p; float b;
clrscr();&lt;/pre&gt;instead of this one:&lt;pre class="sourcecode"&gt;clrscr();
float a=1; int p; float b;&lt;/pre&gt;Hope that helps.&lt;br /&gt;
&lt;br /&gt;
#7&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/353722/353727/re-is-this-codee-alright-/#353727</guid>
      <pubDate>Fri, 09 Feb 2007 05:30:52 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: is this codee alright ?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/353722/353728/re-is-this-codee-alright-/#353728</link>
      <description>main() is of return type int&lt;br /&gt;
See references at &lt;a href="http://www.codepedia.com/1/CMain"&gt;http://www.codepedia.com/1/CMain&lt;/a&gt;&lt;br /&gt;
bilderbikkel&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/353722/353728/re-is-this-codee-alright-/#353728</guid>
      <pubDate>Fri, 09 Feb 2007 05:39:09 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: is this codee alright ?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/353722/353729/re-is-this-codee-alright-/#353729</link>
      <description>: main() is of return type int&lt;br /&gt;
: See references at &lt;a href="http://www.codepedia.com/1/CMain"&gt;http://www.codepedia.com/1/CMain&lt;/a&gt;&lt;br /&gt;
: bilderbikkel&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
Yeah. Although I think the Turbo C 2.01 C compiler accepts main to have a void return type. It's not a good programming practice, though, I think, since the OS has no way to know whether the program terminated normally.&lt;br /&gt;
&lt;br /&gt;
#7&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/353722/353729/re-is-this-codee-alright-/#353729</guid>
      <pubDate>Fri, 09 Feb 2007 05:50:08 -0700</pubDate>
      <category>C and C++</category>
    </item>
    <item>
      <title>Re: is this codee alright ?</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/353722/353755/re-is-this-codee-alright-/#353755</link>
      <description>: Correct me if I am wrong (grammatical errors too) but I think there is a &lt;span style="color: Red;"&gt;logic error&lt;/span&gt; in this program. One more thing, variable declarations should come before any other statement. In other words, do this:&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;float a=1; int p; float b;
: clrscr();&lt;/pre&gt;instead of this one:&lt;pre class="sourcecode"&gt;clrscr();
: float a=1; int p; float b;&lt;/pre&gt;Hope that helps.&lt;br /&gt;
: &lt;br /&gt;
: #7&lt;br /&gt;
: &lt;br /&gt;
Good going, spotting that base/exponent mix-up!&lt;br /&gt;
&lt;br /&gt;
Where to place declarations depends on wether you're writing C or C++. For C they have to come at the beginning of the function, like you said, for C++ they can come in other places as well.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/353722/353755/re-is-this-codee-alright-/#353755</guid>
      <pubDate>Fri, 09 Feb 2007 16:56:51 -0700</pubDate>
      <category>C and C++</category>
    </item>
  </channel>
</rss>