





<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Durofy &#187; Programming</title>
	<atom:link href="http://www.durofy.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.durofy.com</link>
	<description>Engineering &#38; Technology Blog</description>
	<lastBuildDate>Sun, 05 Feb 2012 04:41:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Decimal to Binary Converter in C</title>
		<link>http://www.durofy.com/programming/decimal-to-binary-converter-in-c/</link>
		<comments>http://www.durofy.com/programming/decimal-to-binary-converter-in-c/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 21:28:53 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c program convert decimal to binary]]></category>
		<category><![CDATA[c programming question]]></category>
		<category><![CDATA[decimal to binary]]></category>
		<category><![CDATA[decimal to binary application]]></category>
		<category><![CDATA[decimal to binary c program]]></category>
		<category><![CDATA[decimal to binary converter]]></category>
		<category><![CDATA[decimal to binary converter c program]]></category>
		<category><![CDATA[decimal to binary converter free]]></category>
		<category><![CDATA[decimal to binary converter in c]]></category>
		<category><![CDATA[free decimal to binary converter download]]></category>
		<category><![CDATA[program converters decimal to binary]]></category>
		<category><![CDATA[program to convert decimal to binary]]></category>

		<guid isPermaLink="false">http://zarrata.com/durofy/?p=1053</guid>
		<description><![CDATA[This program converts decimal to binary numbers. It works for positive integers 0-127. To see how conversions between number systems work, read the post on The Decimal, Binary, Octal &#38; Hexadecimal Number Systems Executable - Download decimal2binary.exe Code - #include&#60;stdio.h&#62; #include&#60;conio.h&#62; /* program to convert decimal to binary - works for positive numbers 0-127 */ int [...]]]></description>
			<content:encoded><![CDATA[<p>This program converts decimal to binary numbers. It works for positive integers 0-127. To see how conversions between number systems work, read the post on <a href="http://zarrata.com/durofy/computers/the-decimal-binary-octal-hexadecimal-number-systems/">The Decimal, Binary, Octal &amp; Hexadecimal Number Systems</a></p>
<p><strong>Executable </strong>- Download <a href="http://zarrata.com/files/decimal2binary.exe">decimal2binary.exe</a></p>
<p><strong>Code </strong>-</p>
<pre class="brush:cpp">#include&lt;stdio.h&gt;
#include&lt;conio.h&gt;

/* program to convert decimal to binary
- works for positive numbers 0-127 */

int main()
{
    int x, i=0;
    printf("Enter the decimal number\n");
    scanf("%d", &amp;x);
    int y=x;
    int j=0;
    /* this loop gets a count of the number of bigits/remainders */
    while(x!=0)
    {
      i=x%2;
      x=x/2;
      j++;
    }
    x=y;
    int n=0, a[n];
    /* second loop feeds values of bigits to array */
    while(n&lt;j &amp;&amp; x!=0)
    {
      i=x%2;
      x=x/2;
      a[n]=i;
      n++;
    }
    n=0;
    printf("The binary equivalent is ");
    /* third loop prints the reversed array */
    while(n&lt;j)
    {
      printf("%d", a[j-(n+1)]);
      n++;
    }
    getch();
    return 0;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/decimal-to-binary-converter-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calender Program in C</title>
		<link>http://www.durofy.com/programming/calender-program-in-c/</link>
		<comments>http://www.durofy.com/programming/calender-program-in-c/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 21:26:10 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c calender]]></category>
		<category><![CDATA[c program calender]]></category>
		<category><![CDATA[c program month year calender]]></category>
		<category><![CDATA[c program question]]></category>
		<category><![CDATA[c puzzle]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>
		<category><![CDATA[calender]]></category>
		<category><![CDATA[calender program]]></category>
		<category><![CDATA[calender program in c]]></category>
		<category><![CDATA[month year calender]]></category>
		<category><![CDATA[write a program]]></category>

		<guid isPermaLink="false">http://zarrata.com/durofy/?p=1044</guid>
		<description><![CDATA[Found this question on a C Programming Fan Page on Facebook. Decided to give it a shot. Problem Statement : Write A Program that receives the month and year from the keyword as integers &#38; prints the calendar in the following format. Input : Month, Year Output: Mon Tue Wed Thu Fri Sat Sun 1 [...]]]></description>
			<content:encoded><![CDATA[<p>Found this question on a <a title="C Programming" href="http://www.facebook.com/Programming.c.in">C Programming Fan Page</a> on Facebook. Decided to give it a shot.</p>
<p><strong>Problem Statement</strong> : Write A Program that receives the month and year from the keyword as integers &amp; prints the calendar in the following format.</p>
<p>Input : Month, Year</p>
<p>Output:<br />
Mon Tue Wed Thu Fri Sat Sun<br />
1 2 3 4 5 6 7<br />
8 9 10 11 12 13 14<br />
15 16 17 18 19 20 21<br />
22 23 24 25 26 27 28<br />
29 30 31</p>
<hr />
<p>Adding a link to the first executable. Will post the source code soon - needs some big time improvement.</p>
<p><strong>Note</strong> - It doesn't work for certain leap years. Will fix it and update soon.</p>
<p><strong>Download</strong> - <a href="http://zarrata.com/files/month_year_calender.exe">calender.exe</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/calender-program-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASCII Values &amp; Table Generator in C</title>
		<link>http://www.durofy.com/programming/ascii-values-table-generator-in-c/</link>
		<comments>http://www.durofy.com/programming/ascii-values-table-generator-in-c/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 18:05:11 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ascii c programming]]></category>
		<category><![CDATA[ascii decimal hexadecimal octal]]></category>
		<category><![CDATA[ascii generator]]></category>
		<category><![CDATA[ascii program in c]]></category>
		<category><![CDATA[ascii table]]></category>
		<category><![CDATA[ascii table generator]]></category>
		<category><![CDATA[ascii table program]]></category>
		<category><![CDATA[ascii value generator]]></category>
		<category><![CDATA[ascii values]]></category>
		<category><![CDATA[ascii values c program]]></category>
		<category><![CDATA[c program ascii]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>
		<category><![CDATA[character ascii value]]></category>
		<category><![CDATA[program find ascii value]]></category>

		<guid isPermaLink="false">http://www.zarrata.com/coderaft/?p=142</guid>
		<description><![CDATA[What are ASCII values? Why are they needed? We are all aware of the fact that all computers understand is 0 &#38; 1 - and everything else is stored as patterns containing 0's and 1's. Some of us also know that numbers like 25, 12, etc can be represented as patterns of 0's &#38; 1's. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What are ASCII values? Why are they needed?</strong><br />
We are all aware of the fact that all computers understand is 0 &amp; 1 - and everything else is stored as patterns containing 0's and 1's. Some of us also know that numbers like 25, 12, etc can be represented as patterns of 0's &amp; 1's. The computer interprets 25 as 11001 and 12 as 1100.  But how does it interpret a  sentence like "My name is K" or a word like "name" or a letter like "K"? Also, how does it know the difference between 'k' &amp; 'K'?</p>
<p>This is where ASCII values come in. Each character (including a space) has a certain corresponding number associated to it. And there are different numbers assigned to the lower and upper case of the same alphabet.  For instance, the letter 'a' corresponds to the number 97 while 'A' corresponds to the number 65.</p>
<p>An ASCII table maps the characters to the numbers. Apart from the equivalent decimal representation, it also gives the hexadecimal and octal representations of the character.</p>
<p>This is what the ASCII table looks like -</p>
<p><img class="alignnone" title="ascii_value_table" src="http://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Ascii_Table-nocolor.svg/1000px-Ascii_Table-nocolor.svg.png" alt="ascii value table" width="600" height="418" /></p>
<p>Here's a<a title="ascii_values" href="http://www.asciivalue.com/" target="_blank"> little tool</a> that can help you experiment with ASCII values.</p>
<p><strong>What's it got to do with programming?</strong></p>
<p>Now, the more important question. What has your programming got to do with ASCII values?<br />
To begin with, have a look at the following C code -</p>
<blockquote><p><span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">char</span> c<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter any character</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%c</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>c<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/*scans a character */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> c<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints a decimal */</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p>It scans a character and returns an integer. Do you think the code is incorrect? Try compiling it. It does return a number for every character. And what is this number? Exactly, the decimal ASCII value of the character. Don't believe me? That's what the table is for.</p>
<blockquote><p>Note that <strong>%d</strong> is responsible for giving us the corresponding decimal value from the ASCII table. We could similarly use <span style="color: #000000;">%x to hexadecimal and %o for octal values corresponding to the character.<br />
</span></p></blockquote>
<p>Now, we could try doing it the other way round. Input a number and get the corresponding character, that is.</p>
<blockquote><p><span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> d<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter any number</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>d<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* scans a decimal */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%c</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> d<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints a character */</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p>That's not it. We may even generate the complete column for a character from the ASCII table. All we need to do is print the dec, hex and oct equivalents for the input character.</p>
<blockquote><p><span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">char</span> c<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter any character\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%c</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>c<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/*scans a character */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d\</span><span style="color: #0f69ff;">t</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> c<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints dec */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%x\</span><span style="color: #0f69ff;">t</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> c<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints hex */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%o</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> c<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints oct */</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p>Now, we can easily use a loop to generate the complete ASCII table. The above table ends at the dec value 127. However, the extended ASCII table is defined to the decimal value 255(ie - it has 256 values). See <a href="http://www.cdrummond.qc.ca/cegep/informat/Professeurs/Alain/files/ascii.htm">this link</a> for the extended ASCII table.</p>
<div class="run-this">
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #696969;">/* program to generate the complete ASCII table */</span><br />
<span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> x<span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">for</span><span style="color: #808030;">(</span>x<span style="color: #808030;">=</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span>x<span style="color: #808030;">&lt;</span><span style="color: #808030;">=</span><span style="color: #008c00;">255</span><span style="color: #800080;">;</span>x<span style="color: #808030;">+</span><span style="color: #808030;">+</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">\n</span><span style="color: #0f69ff;">%c\</span><span style="color: #0f69ff;">t</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> x<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints char */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d\</span><span style="color: #0f69ff;">t</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> x<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints dec */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%x\</span><span style="color: #0f69ff;">t</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> x<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints hex */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%o</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> x<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* prints oct */</span><br />
<span style="color: #800080;">}</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
</div>
<p>You can now try experimenting with ASCII values, decimal, hex, octal and characters. Good Luck!<br />
{Btw, Just to let you know - ASCII stands for American Standard Code for Information Interchange}</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/ascii-values-table-generator-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Logic to Find Exponents with Integral Powers</title>
		<link>http://www.durofy.com/programming/c-logic-tutorial-to-find-exponents-with-integral-powers/</link>
		<comments>http://www.durofy.com/programming/c-logic-tutorial-to-find-exponents-with-integral-powers/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 18:46:42 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c exponents]]></category>
		<category><![CDATA[c power]]></category>
		<category><![CDATA[c program to calculate power]]></category>
		<category><![CDATA[c programming example]]></category>
		<category><![CDATA[c programming power function]]></category>
		<category><![CDATA[c programming tutorial]]></category>
		<category><![CDATA[c programming tutotrial]]></category>
		<category><![CDATA[c sample program]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>
		<category><![CDATA[c++ tutorial]]></category>
		<category><![CDATA[exponents logic]]></category>
		<category><![CDATA[find power c programming]]></category>
		<category><![CDATA[finding exponential value]]></category>

		<guid isPermaLink="false">http://www.zarrata.com/coderaft/?p=93</guid>
		<description><![CDATA[If you've noticed, In C Programming, you cannot use a^b directly to find the value of an exponent. Although, there is a pow(a, b) function that gives you the result. But, it's always nice to work with the basic logic. If you look at the definition of an exponential: "Exponentiation is a mathematical operation, written [...]]]></description>
			<content:encoded><![CDATA[<p>If you've noticed, In C Programming, you cannot use <strong>a^b</strong> directly to find the value of an exponent. Although, there is a <strong>pow(a, b) </strong>function that gives you the result. But, it's always nice to work with the basic logic.</p>
<p>If you look at the definition of an exponential:</p>
<blockquote><p>"Exponentiation is a mathematical operation, written as a^n. When n is a positive integer, exponentiation corresponds to repeated multiplication." - <a href="http://en.wikipedia.org/wiki/Exponentiation">Wikipedia</a></p></blockquote>
<p>We're gonna work out our logic using this very basic definition [<em>especially the part where it says</em> - exponentiation corresponds to repeated multiplication ;)]</p>
<p>Code:</p>
<blockquote><p><span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> base<span style="color: #808030;">,</span> index<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter the base\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* say, 2 */</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>base<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter the index\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* say, 3 */</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>index<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #696969;">/* always remember that 2^3 is actually 2x2x2 ie-2 multiplied by itself 3 times */</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> i<span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">int</span> power<span style="color: #808030;">=</span>base<span style="color: #800080;">;</span> <span style="color: #696969;">/* power is initiallized to 2 */</span><br />
<span style="color: #800000; font-weight: bold;">for</span><span style="color: #808030;">(</span>i<span style="color: #808030;">=</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span>i<span style="color: #808030;">&lt;</span>index<span style="color: #800080;">;</span>i<span style="color: #808030;">+</span><span style="color: #808030;">+</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
power<span style="color: #808030;">=</span>power<span style="color: #808030;">*</span>base<span style="color: #800080;">;</span> <span style="color: #696969;">/* 1st loop : power = 2*2, 2nd loop : power =(2*2)*2 */</span><br />
<span style="color: #800080;">}</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"\</span><span style="color: #0f69ff;">n</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> power<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p>It's pretty easy to understand using an example. Refer to the example in comments to see how the code works. Also, this is not the only way. Think of how you could achieve the same with a different (and perhaps, better) code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/c-logic-tutorial-to-find-exponents-with-integral-powers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Quiz Program in C</title>
		<link>http://www.durofy.com/programming/c-application-basic-quiz-on-c-programming/</link>
		<comments>http://www.durofy.com/programming/c-application-basic-quiz-on-c-programming/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 20:37:06 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c code quiz]]></category>
		<category><![CDATA[c programming example]]></category>
		<category><![CDATA[c programming quiz]]></category>
		<category><![CDATA[c programming quiz code]]></category>
		<category><![CDATA[c programming tutotrial]]></category>
		<category><![CDATA[c quiz]]></category>
		<category><![CDATA[c quiz application]]></category>
		<category><![CDATA[c quiz code]]></category>
		<category><![CDATA[c sample program]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>
		<category><![CDATA[quiz program in c]]></category>
		<category><![CDATA[quiz programming]]></category>

		<guid isPermaLink="false">http://www.zarrata.com/coderaft/?p=90</guid>
		<description><![CDATA[This is a program for a simple quiz on the C Programming Language. It can be modified to be made into a quiz on any topic. It includes negative marking for wrong answers, keeps track of the score &#38; displays it at the end of the quiz. #include &#60;stdio.h&#62; #include &#60;conio.h&#62; main() { int score=0; [...]]]></description>
			<content:encoded><![CDATA[<p>This is a program for a simple quiz on the C Programming Language. It can be modified to be made into a quiz on any topic. It includes negative marking for wrong answers, keeps track of the score &amp; displays it at the end of the quiz.</p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> score<span style="color: #808030;">=</span><span style="color: #008c00;">0</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">int</span> answer<span style="color: #800080;">;</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Welcome to the C quiz</span><span style="color: #0f69ff;">\n</span><span style="color: #0000e6;">The quiz has 5 very basic questions on the C Programming Language. You get +3 for each correct answer &amp; -1 for each wrong/invalid answer.\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Q1) Why is it called 'C' &amp; not 'D'?</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">[1]C stands for code\</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[2]The inventor's name started with a C</span><span style="color: #0f69ff;">\n</span><span style="color: #0000e6;">[3]It developed after a language called 'B'\</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[4]Why should I care?</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>answer<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>answer<span style="color: #808030;">=</span><span style="color: #808030;">=</span><span style="color: #008c00;">3</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">That's Correct!\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">+</span><span style="color: #008c00;">3</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
<span style="color: #800000; font-weight: bold;">else</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Wrong Answer</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">-</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">\n</span><span style="color: #0000e6;">Q) It was developed at?</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">[1]IBM</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[2]Bell Labs</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">[3]MIT</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[4]Microsoft(?)\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>answer<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>answer<span style="color: #808030;">=</span><span style="color: #808030;">=</span><span style="color: #008c00;">2</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">That's Correct!</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">+</span><span style="color: #008c00;">3</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
<span style="color: #800000; font-weight: bold;">else</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Wrong Answer\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">-</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Q) Which of these is not a C keyword as per ANSI C ?\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">[1]extern</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[2]volatile</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">[3]enter</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[4]break</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>answer<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>answer<span style="color: #808030;">=</span><span style="color: #808030;">=</span><span style="color: #008c00;">3</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">That's Correct!</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">+</span><span style="color: #008c00;">3</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
<span style="color: #800000; font-weight: bold;">else</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Wrong Answer</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">-</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Q) What is ANSI, btw? ?</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">[1]Area of Natural and Scientific Interest\</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[2]American National Standards Institute\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">[3]American National Standardization Institute\</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[4]American National Society Of Intellectuals\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>answer<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>answer<span style="color: #808030;">=</span><span style="color: #808030;">=</span><span style="color: #008c00;">2</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">That's Correct!\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">+</span><span style="color: #008c00;">3</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
<span style="color: #800000; font-weight: bold;">else</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Wrong Answer\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">-</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">\n</span><span style="color: #0000e6;">Q)Which of these concepts is NOT supported by C ?\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">[1]Pointers</span><span style="color: #0f69ff;">\t</span><span style="color: #0000e6;">[2]Functions\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">[3]Strings\</span><span style="color: #0f69ff;">t</span><span style="color: #0000e6;">[4]Namespaces\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>answer<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>answer<span style="color: #808030;">=</span><span style="color: #808030;">=</span><span style="color: #008c00;">4</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">That's Correct!</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">+</span><span style="color: #008c00;">3</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
<span style="color: #800000; font-weight: bold;">else</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Wrong Answer</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
score<span style="color: #808030;">=</span>score<span style="color: #808030;">-</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Thank You for taking the Quiz.\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;"> Your Total Score is </span><span style="color: #0f69ff;">%d</span><span style="color: #0000e6;"> out of 15</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> score<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p>getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800080;">}</span></p></blockquote>
<p><a href="http://zarrata.com/files/c_quiz.exe"><strong>Download the Application (.exe)</strong> </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/c-application-basic-quiz-on-c-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Personal Fitness &amp; Weight Analyzer in C</title>
		<link>http://www.durofy.com/programming/c-application-personal-fitness-weight-analyzer/</link>
		<comments>http://www.durofy.com/programming/c-application-personal-fitness-weight-analyzer/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 07:03:37 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bmi]]></category>
		<category><![CDATA[bmi calculator]]></category>
		<category><![CDATA[c program fitness]]></category>
		<category><![CDATA[c program weight loss]]></category>
		<category><![CDATA[c programming example]]></category>
		<category><![CDATA[c programming tutotrial]]></category>
		<category><![CDATA[c sample program]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>
		<category><![CDATA[fitness]]></category>
		<category><![CDATA[fitness analysis]]></category>
		<category><![CDATA[weight analysis]]></category>
		<category><![CDATA[weight loss]]></category>
		<category><![CDATA[weight loss application]]></category>

		<guid isPermaLink="false">http://www.zarrata.com/coderaft/?p=85</guid>
		<description><![CDATA[This C Program Analyzes if you're underweight, overweight or obese and accordingly suggests you to gain or lose the right amount of weight in the right period of time. #include &#60;stdio.h&#62; #include &#60;conio.h&#62; #include &#60;math.h&#62; main() { int weight; printf("Welcome to your Weight Analyser\n"); printf("To begin, Enter your current weight in pounds(lbs)\n\n"); scanf("%d", &#38;weight); printf("You [...]]]></description>
			<content:encoded><![CDATA[<p>This C Program Analyzes if you're underweight, overweight or obese and accordingly suggests you to gain or lose the right amount of weight in the right period of time.</p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">math.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> weight<span style="color: #800080;">;</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Welcome to your Weight Analyser\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">To begin, Enter your current weight in pounds(lbs)</span><span style="color: #0f69ff;">\n</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>weight<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">You currently have </span><span style="color: #0f69ff;">%d</span><span style="color: #0000e6;"> calories inside you.. In other words, If you lose </span><span style="color: #0f69ff;">%d</span><span style="color: #0000e6;"> calories, you'll dissapear altogether ;) Just Sayin!</span><span style="color: #0f69ff;">\n</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> weight<span style="color: #808030;">*</span><span style="color: #808030;">(</span><span style="color: #008c00;">3500</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> weight<span style="color: #808030;">*</span><span style="color: #808030;">(</span><span style="color: #008c00;">3500</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> height_ft<span style="color: #808030;">,</span> height_in<span style="color: #800080;">;</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Now, to calculate your ideal weight, Enter your height.. How many feet?)</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>height_ft<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">And inches?</span><span style="color: #0f69ff;">n</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>height_in<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> bmi<span style="color: #808030;">=</span><span style="color: #808030;">(</span><span style="color: #008c00;">703</span><span style="color: #808030;">*</span>weight<span style="color: #808030;">)</span><span style="color: #808030;">/</span>pow<span style="color: #808030;">(</span><span style="color: #808030;">(</span><span style="color: #808030;">(</span>height_ft<span style="color: #808030;">)</span><span style="color: #808030;">*</span><span style="color: #008c00;">12</span><span style="color: #808030;">+</span><span style="color: #808030;">(</span>height_in<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span><span style="color: #808030;">(</span><span style="color: #008c00;">2</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span>bmi<span style="color: #808030;">&lt;</span><span style="color: #008000;">18.5</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">You're underweight, You need to gain weight.. How does that feel?</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p><span style="color: #800000; font-weight: bold;">else</span> <span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span><span style="color: #008000;">18.5</span><span style="color: #808030;">&lt;</span>bmi <span style="color: #808030;">&amp;</span><span style="color: #808030;">&amp;</span> bmi<span style="color: #808030;">&lt;</span><span style="color: #008c00;">25</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">You don really need to lose any weight, Your height and weight are in proportion! :)\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p><span style="color: #800000; font-weight: bold;">else</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">if</span><span style="color: #808030;">(</span><span style="color: #008c00;">25</span><span style="color: #808030;">&lt;</span>bmi <span style="color: #808030;">&amp;</span><span style="color: #808030;">&amp;</span> bmi<span style="color: #808030;">&lt;</span><span style="color: #008c00;">30</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">You're overweight! :) Let's see what I can do you make you live longer and happier :).. \</span><span style="color: #0f69ff;">n\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
<span style="color: #800000; font-weight: bold;">else</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">How do you even breathe? You're obese and sick! But I can help.</span><span style="color: #0f69ff;">\n</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> ideal_weight<span style="color: #808030;">=</span><span style="color: #808030;">(</span><span style="color: #008000;">24.9</span><span style="color: #808030;">/</span><span style="color: #008c00;">703</span><span style="color: #808030;">)</span><span style="color: #808030;">*</span><span style="color: #808030;">(</span>pow<span style="color: #808030;">(</span><span style="color: #808030;">(</span><span style="color: #808030;">(</span>height_ft<span style="color: #808030;">)</span><span style="color: #808030;">*</span><span style="color: #008c00;">12</span><span style="color: #808030;">+</span><span style="color: #808030;">(</span>height_in<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span><span style="color: #808030;">(</span><span style="color: #008c00;">2</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Considering your height will not increase anymore, For your ideal weight, You should reduce to </span><span style="color: #0f69ff;">%d</span><span style="color: #0000e6;"> \</span><span style="color: #0f69ff;">n\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> ideal_weight<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Which means you'll need to shed </span><span style="color: #0f69ff;">%d</span><span style="color: #0000e6;"> pounds</span><span style="color: #0f69ff;">\n\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> weight<span style="color: #808030;">-</span>ideal_weight<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">For healthy weight loss, you should take </span><span style="color: #0f69ff;">%d</span><span style="color: #0000e6;"> days to do this by losing 500 calories each day</span><span style="color: #0f69ff;">\n\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #008c00;">7</span><span style="color: #808030;">*</span><span style="color: #808030;">(</span>weight<span style="color: #808030;">-</span>ideal_weight<span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">To do this, make sure that the calories you burn everyday are 500 more than the total calories you take in everyday.\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;"> Good Luck </span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800080;">}</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800080;">}</span></p></blockquote>
<p><a href="http://zarrata.com/files/fitness.exe"><strong>Download the Application (.exe)</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/c-application-personal-fitness-weight-analyzer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arithmetic Progression Generator in C</title>
		<link>http://www.durofy.com/programming/application-arithmetic-progression-generator/</link>
		<comments>http://www.durofy.com/programming/application-arithmetic-progression-generator/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 06:35:49 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ap generator]]></category>
		<category><![CDATA[ap generator code]]></category>
		<category><![CDATA[arithmetic progression]]></category>
		<category><![CDATA[arithmetic progression code in c]]></category>
		<category><![CDATA[c programming example]]></category>
		<category><![CDATA[c programming tutotrial]]></category>
		<category><![CDATA[c sample program]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>

		<guid isPermaLink="false">http://www.zarrata.com/coderaft/?p=71</guid>
		<description><![CDATA[This application generates an AP series using a while loop by specifying the first term, common difference and the number of terms. #include &#60;stdio.h&#62; #include &#60;conio.h&#62; int main(void) { int repeat=1; while(repeat==1) { int a, d, n; printf("Enter first term\n"); scanf("%d", &#38;a); printf("Enter the common difference\n"); scanf("%d", &#38;d); printf("Enter number of terms\n"); scanf("%d", &#38;n); while(n&#62;0) [...]]]></description>
			<content:encoded><![CDATA[<p>This application generates an AP series using a while loop by specifying the first term, common difference and the number of terms.</p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> <span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">void</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> repeat<span style="color: #808030;">=</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">while</span><span style="color: #808030;">(</span>repeat<span style="color: #808030;">=</span><span style="color: #808030;">=</span><span style="color: #008c00;">1</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> a<span style="color: #808030;">,</span> d<span style="color: #808030;">,</span> n<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter first term</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>a<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter the common difference</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>d<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter number of terms\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>n<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">while</span><span style="color: #808030;">(</span>n<span style="color: #808030;">&gt;</span><span style="color: #008c00;">0</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #0f69ff;">t</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> a<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
a<span style="color: #808030;">=</span>a<span style="color: #808030;">+</span>d<span style="color: #800080;">;</span><br />
n<span style="color: #808030;">=</span>n<span style="color: #808030;">-</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">\n\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Repeat[1]\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Exit[0\]</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>repeat<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p><a href="http://zarrata.com/files/while_ap_generator.exe"><strong>Download the Application (.exe) </strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/application-arithmetic-progression-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Menu-Based Calculator in C</title>
		<link>http://www.durofy.com/programming/application-basic-calculator/</link>
		<comments>http://www.durofy.com/programming/application-basic-calculator/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 06:30:48 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[basic calculator]]></category>
		<category><![CDATA[c programming calculator]]></category>
		<category><![CDATA[c programming example]]></category>
		<category><![CDATA[c programming tutotrial]]></category>
		<category><![CDATA[c sample program]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>
		<category><![CDATA[calculator]]></category>
		<category><![CDATA[calculator c]]></category>
		<category><![CDATA[calculator c program]]></category>
		<category><![CDATA[calculator code in c]]></category>
		<category><![CDATA[calculator in c]]></category>
		<category><![CDATA[calculator program]]></category>
		<category><![CDATA[download calculator]]></category>

		<guid isPermaLink="false">http://www.zarrata.com/coderaft/?p=68</guid>
		<description><![CDATA[Here's the code for a Basic Calculator Using Switch Statements: #include &#60;stdio.h&#62; #include &#60;conio.h&#62; int main(void) { int a, b; int repeat=1; printf("Welcome to the C calculator\nEnter any two numbers\n"); scanf("%d%d", &#38;a, &#38;b); while(repeat==1) { int choice; printf("Choose the operation to be performed\nDivision[1]\nMultiplication[2]\nAddition[3]\nSubtraction[4]\n"); scanf("%d", &#38;choice); int result; switch(choice) { case 1: result = a/b; printf("The [...]]]></description>
			<content:encoded><![CDATA[<p>Here's the code for a Basic Calculator Using Switch Statements:</p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> <span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">void</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> a<span style="color: #808030;">,</span> b<span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">int</span> repeat<span style="color: #808030;">=</span><span style="color: #008c00;">1</span><span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Welcome to the C calculator\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Enter any two numbers\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>a<span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>b<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">while</span><span style="color: #808030;">(</span>repeat<span style="color: #808030;">=</span><span style="color: #808030;">=</span><span style="color: #008c00;">1</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> choice<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Choose the operation to be performed</span><span style="color: #0f69ff;">\n</span><span style="color: #0000e6;">Division[1]</span><span style="color: #0f69ff;">\n</span><span style="color: #0000e6;">Multiplication[2]\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Addition[3]</span><span style="color: #0f69ff;">\n</span><span style="color: #0000e6;">Subtraction[4]\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>choice<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> result<span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">switch</span><span style="color: #808030;">(</span>choice<span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">case </span><span style="color: #008c00;">1</span><span style="color: #e34adc;">:</span><br />
result <span style="color: #808030;">=</span> a<span style="color: #808030;">/</span>b<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">The quotient is </span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> result<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">break</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">case </span><span style="color: #008c00;">2</span><span style="color: #e34adc;">:</span><br />
result <span style="color: #808030;">=</span> a<span style="color: #808030;">*</span>b<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">The product is </span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> result<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">break</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">case </span><span style="color: #008c00;">3</span><span style="color: #e34adc;">:</span><br />
result <span style="color: #808030;">=</span> a<span style="color: #808030;">+</span>b<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">The sum is </span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> result<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">break</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">case </span><span style="color: #008c00;">4</span><span style="color: #e34adc;">:</span><br />
result <span style="color: #808030;">=</span> a<span style="color: #808030;">-</span>b<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">The difference is </span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> result<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">break</span><span style="color: #800080;">;</span><br />
<span style="color: #e34adc;"> </span><span style="color: #800000; font-weight: bold;">default</span><span style="color: #e34adc;">:</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Please enter a valid choice</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">break</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">\n</span><span style="color: #0000e6;">Repeat[1]\</span><span style="color: #0f69ff;">n</span><span style="color: #0000e6;">Exit[0]</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>repeat<span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p><a href="zarrata.com/files/switch_calculator.exe"><strong>Download the Application (.exe)</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/application-basic-calculator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C Tutorial 6] Performing Operations on the Input</title>
		<link>http://www.durofy.com/programming/tutorial-6-performing-operations-on-the-input/</link>
		<comments>http://www.durofy.com/programming/tutorial-6-performing-operations-on-the-input/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 15:09:00 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c function to take input]]></category>
		<category><![CDATA[c programming example]]></category>
		<category><![CDATA[c programming scanf]]></category>
		<category><![CDATA[c programming tutotrial]]></category>
		<category><![CDATA[c sample program]]></category>
		<category><![CDATA[c scanf]]></category>
		<category><![CDATA[c taking user input]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>
		<category><![CDATA[scanf %d]]></category>
		<category><![CDATA[scanf function]]></category>
		<category><![CDATA[scanf input function]]></category>
		<category><![CDATA[taking input c code]]></category>

		<guid isPermaLink="false">http://www.zarrata.com/cprogramming/?p=51</guid>
		<description><![CDATA[Once we get the input(s) from the user [Tutorial 5], it is time to modify the input by performing operations on it. The basic idea of coding is to design systems which perform various functions. And a function is nothing but a machine that gives output values for various input values. Since our basic aim [...]]]></description>
			<content:encoded><![CDATA[<p>Once we get the input(s) from the user [Tutorial 5],  it is time to modify the input by performing operations on it. The basic idea of coding is to design systems which perform various functions. And a function is nothing but a machine that gives output values for various input values.</p>
<p>Since our basic aim is to implement functions, we need to perform operations on the inputs to get outputs. Now, suppose you had to code a basic machine that adds 5 to the input.</p>
<p><img src="https://lh5.googleusercontent.com/-YrrzBxkf1Qw/ThHZNAxzgXI/AAAAAAAAAHk/WZTItxklq4k/s800/function.gif" alt="function" /></p>
<p>You will need to:</p>
<p><strong>Step 1</strong> : <em>Get an input value from the user</em></p>
<p><strong>Step 2</strong> :<em> Add 5 to the input</em></p>
<p><strong>Step 3 </strong>: <em>Display output to the user</em></p>
<p><strong>Method 1 -</strong></p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> <span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> x<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter any number\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;"> /* Step 1 */</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>x<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> y<span style="color: #800080;">;</span><br />
y<span style="color: #808030;">=</span>x<span style="color: #808030;">+</span><span style="color: #008c00;">5</span><span style="color: #800080;">;</span> <span style="color: #696969;"> /* Step 2 */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">The output is </span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> y<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;"> /* Step 3 */</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">return</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p>In the above method, we have used two variables. x for the input and y for the output. However, we can add 5 to change the input itself and display it as the output (this is the power of programming, the otherwise constant inputs are variables in a program)</p>
<p><strong>Method 2 -</strong></p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> <span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> x<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter any number</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;"> /* Step 1 */</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>x<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p>x<span style="color: #808030;">=</span>x<span style="color: #808030;">+</span><span style="color: #008c00;">5</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 2 */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">The output is </span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> x<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 3 */</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">return</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p>Now, don't get confused when you see x=x+5; Just remember the following thumb rule :</p>
<blockquote><p>In programming, the value on the right hand side(called the rvalue replaces the value on the left hand side(called the lvalue). In this case, (x+5) replaces x. hence, the new value of x is (x+5).</p></blockquote>
<p>For a more elegant code, we could perform the addition in the printf function itself.</p>
<p><strong>Method 3 -</strong></p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> <span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> x<span style="color: #800080;">;</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter any number\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 1 */</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>x<span style="color: #808030;">)</span><span style="color: #800080;">;</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">The output is </span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> x<span style="color: #808030;">+</span><span style="color: #008c00;">5</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* Steps 2 &amp; 3 */</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">return</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p>In this case, the steps 2 and 3 can be implemented in a single line. As you will realize later, this is what programming is all about. A lot of people can program, but only a few can come up with the most elegant solution. And the most elegant one wins.</p>
<p><em>Note - in the above program, we did not have to define the "+" operator. It is one of the pre-defined C operators. C has a number of mathematical, logical and other operators. (discussed later)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/tutorial-6-performing-operations-on-the-input/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C Tutorial 5] Taking Input From User</title>
		<link>http://www.durofy.com/programming/tutorial-5-taking-input-from-user/</link>
		<comments>http://www.durofy.com/programming/tutorial-5-taking-input-from-user/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 06:13:07 +0000</pubDate>
		<dc:creator>Rishabh Dev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c function to take input]]></category>
		<category><![CDATA[c programming example]]></category>
		<category><![CDATA[c programming scanf]]></category>
		<category><![CDATA[c programming tutotrial]]></category>
		<category><![CDATA[c sample program]]></category>
		<category><![CDATA[c scanf]]></category>
		<category><![CDATA[c taking user input]]></category>
		<category><![CDATA[c++ program]]></category>
		<category><![CDATA[c++ programming]]></category>
		<category><![CDATA[console input c program]]></category>
		<category><![CDATA[scanf %d]]></category>
		<category><![CDATA[scanf function]]></category>
		<category><![CDATA[scanf input function]]></category>
		<category><![CDATA[taking input c code]]></category>

		<guid isPermaLink="false">http://www.zarrata.com/cprogramming/?p=25</guid>
		<description><![CDATA[/* how to take input data from the user - so we can later perform operations on it */ Just like printf is used to display output, scanf is its counterpart used to take input from the user. Assume that we need a number as input from the user(you're gonna need them in almost every [...]]]></description>
			<content:encoded><![CDATA[<p>/* how to take input data from the user - so we can later perform operations on it */</p>
<p>Just like <em>printf </em> is used to display output, <em>scanf </em> is its counterpart used to take input from the user. Assume that we need a number as input from the user(you're gonna need them in almost every program you make). We first need to define a variable that will hold the value of this number. A C variable is used to hold a value - it will store the value we take from the user.</p>
<p>So, there are essentially three steps we need to program this :</p>
<p><strong>Step 1</strong> - declare a variable to store value that the user will enter<br />
Syntax - <strong>int a;</strong> declares a variable called a(you can call it anything) of the integer type.</p>
<p><strong>Step 2</strong> - ask the user to enter a value<br />
Syntax - using printf</p>
<p><strong>Step 3</strong> - take the value and store it in the variable<br />
Syntax - <strong>scanf("%d", &amp;a);</strong><br />
<strong>%d</strong> stands for "take the value" and <strong>&amp;a</strong> stands for "store it the variable called a".</p>
<p>The Program :</p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> <span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> a<span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 1 */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter any number\</span><span style="color: #0f69ff;">n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 2 */</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>a<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 3 */</span><br />
getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">return</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
<p>Now, just to check it the program does what it's supposed to do. Let's display the value of a as the output. We just need to add another printf function to the above code :</p>
<blockquote><p><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">stdio.h</span><span style="color: #800000;">&gt;</span><br />
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">conio.h</span><span style="color: #800000;">&gt;</span></p>
<p><span style="color: #800000; font-weight: bold;">int</span> <span style="color: #400000;">main</span><span style="color: #808030;">(</span><span style="color: #808030;">)</span><br />
<span style="color: #800080;">{</span><br />
<span style="color: #800000; font-weight: bold;">int</span> a<span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 1 */</span><br />
printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Enter any number</span><span style="color: #0f69ff;">\n</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 2 */</span><br />
scanf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> <span style="color: #808030;">&amp;</span>a<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* Step 3 */</span></p>
<p>printf<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">The value you entered was </span><span style="color: #0f69ff;">%d</span><span style="color: #800000;">"</span><span style="color: #808030;">,</span> a<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">/* displays the value of a */</span></p>
<p>getch<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span><br />
<span style="color: #800000; font-weight: bold;">return</span> <span style="color: #008c00;">0</span><span style="color: #800080;">;</span><br />
<span style="color: #800080;">}</span></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.durofy.com/programming/tutorial-5-taking-input-from-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

