<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-914290258000324318</atom:id><lastBuildDate>Fri, 25 Oct 2024 08:45:30 +0000</lastBuildDate><category>c</category><category>c language</category><category>c program</category><category>programming</category><category>simple c program</category><category>simple program</category><category>For loop</category><category>Loop counter</category><category>c factorial program</category><category>even or odd</category><category>factorial</category><category>factorial program</category><category>print shape</category><category>sum of digits</category><title>C Simple Programs</title><description>Simple C Programs For Beginners</description><link>http://csimpleprograms.blogspot.com/</link><managingEditor>noreply@blogger.com (Anonymous)</managingEditor><generator>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-914290258000324318.post-2289262974869588412</guid><pubDate>Wed, 03 Jul 2013 18:49:00 +0000</pubDate><atom:updated>2013-07-03T11:49:18.936-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c</category><category domain="http://www.blogger.com/atom/ns#">c language</category><category domain="http://www.blogger.com/atom/ns#">c program</category><category domain="http://www.blogger.com/atom/ns#">programming</category><category domain="http://www.blogger.com/atom/ns#">simple c program</category><category domain="http://www.blogger.com/atom/ns#">simple program</category><category domain="http://www.blogger.com/atom/ns#">sum of digits</category><title>Simple C Program to Calculate Sum of Digits of a Number</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This is a very simple C Language program that calculates the sum of digits of a 5 digit number. The 5 digit number is entered by the user. Here&#39;s the code and output of the program. Enjoy!!!&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;
Code&lt;/h2&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
int main()
{
    int num, d1, d2, d3, d4, d5,sum;
    printf(&quot;Enter a five digit number:&quot;);
    scanf(&quot;%d&quot;,&amp;amp;num);
    d1 = num / 10000;
    d2 = (num % 10000) / 1000;
    d3 = (num % 1000) / 100;
    d4 = (num % 100) / 10;
    d5 = num % 10;
    sum = d1 + d2 + d3 + d4 + d5;
    printf(&quot;sum: %d&quot;, sum);
    return 0;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Output&lt;/h2&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMU-8ved8NO0QiXliMdUKPvosw0jsBjPWXqgaFA6-26DG7XiGIcQHxXZhzOkf5ux3wOl0O6sBjWVWMb758DoBtDMxOZ-hz4MfrHqnt5bLP5jaC6CdGYhbGd3ItxZu8PcaVmVZrN3ZeTW-8/s533/c-program-sum-digits-output.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;230&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMU-8ved8NO0QiXliMdUKPvosw0jsBjPWXqgaFA6-26DG7XiGIcQHxXZhzOkf5ux3wOl0O6sBjWVWMb758DoBtDMxOZ-hz4MfrHqnt5bLP5jaC6CdGYhbGd3ItxZu8PcaVmVZrN3ZeTW-8/s400/c-program-sum-digits-output.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
You can go through the code and in case of any confusion, you can feel free to ask me by using the comment form below.&lt;/div&gt;
&lt;/div&gt;
</description><link>http://csimpleprograms.blogspot.com/2013/07/c-program-sum-digits.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMU-8ved8NO0QiXliMdUKPvosw0jsBjPWXqgaFA6-26DG7XiGIcQHxXZhzOkf5ux3wOl0O6sBjWVWMb758DoBtDMxOZ-hz4MfrHqnt5bLP5jaC6CdGYhbGd3ItxZu8PcaVmVZrN3ZeTW-8/s72-c/c-program-sum-digits-output.JPG" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-914290258000324318.post-8184324579393112143</guid><pubDate>Thu, 27 Jun 2013 08:25:00 +0000</pubDate><atom:updated>2013-06-27T04:57:04.454-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c</category><category domain="http://www.blogger.com/atom/ns#">c language</category><category domain="http://www.blogger.com/atom/ns#">c program</category><category domain="http://www.blogger.com/atom/ns#">even or odd</category><category domain="http://www.blogger.com/atom/ns#">simple c program</category><category domain="http://www.blogger.com/atom/ns#">simple program</category><title>Simple C Program to check if number is Even or Odd</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This is a simple C programs which checks if a given number is even or odd. An even number is one that is completely divisible by 2 and an odd number is one which is not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
C Program: Check if given number is Even or Odd&lt;/h2&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;#include&amp;nbsp;&amp;lt;stdio.h&amp;gt;
int&amp;nbsp;main()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;number;/*Variable&amp;nbsp;Declaration*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf&amp;nbsp;(&quot;Enter&amp;nbsp;any&amp;nbsp;number:&amp;nbsp;&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;scanf&amp;nbsp;(&quot;%d&quot;,&amp;nbsp;&amp;amp;number);/*Number&amp;nbsp;input&amp;nbsp;by&amp;nbsp;the&amp;nbsp;user*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(number&amp;nbsp;%&amp;nbsp;2&amp;nbsp;==&amp;nbsp;0)/*Checks&amp;nbsp;if&amp;nbsp;number&amp;nbsp;is&amp;nbsp;divisible&amp;nbsp;by&amp;nbsp;2*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf&amp;nbsp;(&quot;Number&amp;nbsp;is&amp;nbsp;Even&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf&amp;nbsp;(&quot;Number&amp;nbsp;is&amp;nbsp;Odd&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp;0;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Output&lt;/h2&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWVCvAuqlL57gZ90DYY3NTFjDMVHMMto-BYuikXDx6tizwFSNvQzaYRnemVZAVHYmOV4AlBMssygHwaAlNWMQRUTkeObxLPdnEse-06oTrZAHJJH60kOcHVUZVb1iWYP5_r3dI1Bgow1to/s1600/simple-c-program-to-check-if-even-or-odd.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;206&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWVCvAuqlL57gZ90DYY3NTFjDMVHMMto-BYuikXDx6tizwFSNvQzaYRnemVZAVHYmOV4AlBMssygHwaAlNWMQRUTkeObxLPdnEse-06oTrZAHJJH60kOcHVUZVb1iWYP5_r3dI1Bgow1to/s400/simple-c-program-to-check-if-even-or-odd.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
This program uses a single variable &#39;number&#39; which stores the integer that is input by the user. The main task is done by the if statement:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint linenums:8&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(number&amp;nbsp;%&amp;nbsp;2&amp;nbsp;==&amp;nbsp;0)/*Checks&amp;nbsp;if&amp;nbsp;number&amp;nbsp;is&amp;nbsp;divisible&amp;nbsp;by&amp;nbsp;2*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf&amp;nbsp;(&quot;Number&amp;nbsp;is&amp;nbsp;Even&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf&amp;nbsp;(&quot;Number&amp;nbsp;is&amp;nbsp;Odd&quot;);&lt;/pre&gt;
&lt;br /&gt;
The if statement uses modular division. The modular division works slight differently than ordinary division in this way that it gives the remainder. So:&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;16 % 3 = 1&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Therefore, if a number is completely divisible by any number then modular division will give 0.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt; &lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Go through the code and in case of any confusion feel free to ask me by using the contact form below.&lt;/div&gt;
&lt;/div&gt;
</description><link>http://csimpleprograms.blogspot.com/2013/06/c-program-even-or-odd.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWVCvAuqlL57gZ90DYY3NTFjDMVHMMto-BYuikXDx6tizwFSNvQzaYRnemVZAVHYmOV4AlBMssygHwaAlNWMQRUTkeObxLPdnEse-06oTrZAHJJH60kOcHVUZVb1iWYP5_r3dI1Bgow1to/s72-c/simple-c-program-to-check-if-even-or-odd.JPG" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-914290258000324318.post-5274252475477226240</guid><pubDate>Sun, 23 Jun 2013 07:45:00 +0000</pubDate><atom:updated>2013-06-27T00:33:28.197-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c</category><category domain="http://www.blogger.com/atom/ns#">c language</category><category domain="http://www.blogger.com/atom/ns#">c program</category><category domain="http://www.blogger.com/atom/ns#">For loop</category><category domain="http://www.blogger.com/atom/ns#">Loop counter</category><category domain="http://www.blogger.com/atom/ns#">print shape</category><category domain="http://www.blogger.com/atom/ns#">programming</category><title>Simple C Language Program to Print Shapes</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Printing shapes is a common task given to C Language students. It is a good way to capture the main concepts of looping. We&#39;ll discuss different methods to print shapes in C Language using looping. If you get these simple concepts well, then the rest becomes a smooth ride.&lt;br /&gt;
So, let&#39;s start with the show.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;
C Program: Print a Square&lt;/h2&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;#include&amp;nbsp;&amp;lt;stdio.h&amp;gt;
int&amp;nbsp;main()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;n,&amp;nbsp;a,&amp;nbsp;b;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;n&amp;nbsp;=&amp;nbsp;6;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(a=1;a&amp;lt;=n;a++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(b=1;b&amp;lt;=n;b++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&quot;*&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&quot;\n&quot;);}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Output&lt;/h2&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYAI-7cSqwjfELIXJdosnQVg-Qw9iZDjvlhDNox0QAfkozYqz5XjqruOFSOh3oJ3sxTnONtRBTDyVF4GLgHC8kbOa83BEFrPQEUvTSvDiyHnQ5c28wW4d9Ac5McKT1CR6PlcMGN-A8JyMg/s1600/c-language-print-shape.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;202&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYAI-7cSqwjfELIXJdosnQVg-Qw9iZDjvlhDNox0QAfkozYqz5XjqruOFSOh3oJ3sxTnONtRBTDyVF4GLgHC8kbOa83BEFrPQEUvTSvDiyHnQ5c28wW4d9Ac5McKT1CR6PlcMGN-A8JyMg/s400/c-language-print-shape.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
This is very a simple example. The program prints a square with a fixed height and length. It uses three variables n, a and b. &#39;n&#39; specifies the length and height of the square (in number of stars) while a and b are loop counters. The program utilizes the concept of nested For Loops. The main For Loop starts on line 6 and ends on 10.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums:6&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(a=1;a&amp;lt;=n;a++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(b=1;b&amp;lt;=n;b++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&quot;*&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&quot;\n&quot;);}&lt;/pre&gt;
&lt;br /&gt;
In line 6, the first For Loop initializes loop counter &#39;a&#39; to a value of 1. The condition (a &amp;lt;= &amp;nbsp;n) makes sure that the loop is executed &#39;n&#39; number of times. The second For Loop starts at line 8 with the initialization of loop counter &#39;b&#39; to a value of 1. This loop also executes &#39;n&#39; number of times and each time prints an asterisk(*). Thus, printing a whole row. So, each time the first loop executes, the second loop executes &#39;n&#39; number of times and prints an asterisk. The control then returns to the first loop which prints a new line character &#39;\n&#39;. In this way, a square gets printed.&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
C Program: Print a Right Triangle&lt;/h2&gt;
This another simple C program that prints a right triangle, a triangle that contains a right angle. So, here&#39;s the code.&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Code&lt;/h2&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;#include&amp;nbsp;&amp;lt;stdio.h&amp;gt;
int&amp;nbsp;main()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;a=12,&amp;nbsp;b,&amp;nbsp;c;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(b=1&amp;nbsp;;&amp;nbsp;b&amp;lt;=a&amp;nbsp;;&amp;nbsp;b++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(c=1;c&amp;lt;=b;c++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&quot;*&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&quot;\n&quot;);
}
return&amp;nbsp;0;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
Output&lt;/h2&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdtlwA2_p14ftLLgTlf8CeZKFYWWNOclmblOxjyv4yGkbmjklRMl0ElkBuoG1rNbBnM83O-ZhV2RRH1o7_anx7f5hWuKUPqfZCdG2n9emd82jC1a29fZOWMwWWt3WmsH-_gr7CGhtOlmAH/s1600/simple-c-program-triangle-output.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;250&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdtlwA2_p14ftLLgTlf8CeZKFYWWNOclmblOxjyv4yGkbmjklRMl0ElkBuoG1rNbBnM83O-ZhV2RRH1o7_anx7f5hWuKUPqfZCdG2n9emd82jC1a29fZOWMwWWt3WmsH-_gr7CGhtOlmAH/s400/simple-c-program-triangle-output.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
This program works in quite similar fashion as the last one. It also contains nested For Loops. The inner For Loop prints the asterisks while the the outer one prints a newline character (\n) after each row. You can notice that the first row contains one asterisk, the second row two and the third row has three stars. In this way a triangle gets printed.&lt;br /&gt;
&lt;br /&gt;
You can go through the code and in case of any confusion, you can feel free to ask me by using the contact form below.&lt;/div&gt;
</description><link>http://csimpleprograms.blogspot.com/2013/06/print-shape-1.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYAI-7cSqwjfELIXJdosnQVg-Qw9iZDjvlhDNox0QAfkozYqz5XjqruOFSOh3oJ3sxTnONtRBTDyVF4GLgHC8kbOa83BEFrPQEUvTSvDiyHnQ5c28wW4d9Ac5McKT1CR6PlcMGN-A8JyMg/s72-c/c-language-print-shape.JPG" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-914290258000324318.post-1795048962673594765</guid><pubDate>Fri, 21 Jun 2013 07:18:00 +0000</pubDate><atom:updated>2013-06-22T00:48:23.813-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c</category><category domain="http://www.blogger.com/atom/ns#">c factorial program</category><category domain="http://www.blogger.com/atom/ns#">c language</category><category domain="http://www.blogger.com/atom/ns#">c program</category><category domain="http://www.blogger.com/atom/ns#">factorial</category><category domain="http://www.blogger.com/atom/ns#">factorial program</category><category domain="http://www.blogger.com/atom/ns#">programming</category><title>C Program to Find Factorial of a Number</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This is a simple C language program to find factorial of any number. In case you don&#39;t know what factorial is, factorial is the product of an integer and all the integers below it. For example:&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;5! = 1 * 2 * 3 * 4 * 5 = 120&lt;/b&gt;&lt;/div&gt;
The program first prompts for any integer. Then, finds the factorial using For Loop and prints the result.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Code&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;#include&amp;nbsp;&amp;lt;stdio.h&amp;gt;
int&amp;nbsp;main()
{int&amp;nbsp;n,&amp;nbsp;i,&amp;nbsp;fac=1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&quot;Enter&amp;nbsp;any&amp;nbsp;number:&amp;nbsp;&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;scanf(&quot;%d&quot;,&amp;amp;n);&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(i=1;i&amp;lt;=n;i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fac&amp;nbsp;=&amp;nbsp;fac&amp;nbsp;*&amp;nbsp;i;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&quot;Factorial:&amp;nbsp;%d&quot;,&amp;nbsp;fac);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Output&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmZSGJ0EXcTLFZUuBS5axJukcgnXxfRJwDanfARgKig4mBtk22c4EiQnDPciHz4k8e57B7RrmvwxnVmgalUqVso42EdsOhk5cCglki77zT9L-8m7vUgr5FFmkn4jI2XNWsaizwW7sdaD1h/s1600/c-language-factorial-output.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Program Output for C Factorial Program&quot; border=&quot;0&quot; height=&quot;270&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmZSGJ0EXcTLFZUuBS5axJukcgnXxfRJwDanfARgKig4mBtk22c4EiQnDPciHz4k8e57B7RrmvwxnVmgalUqVso42EdsOhk5cCglki77zT9L-8m7vUgr5FFmkn4jI2XNWsaizwW7sdaD1h/s640/c-language-factorial-output.JPG&quot; title=&quot;Program Output for C Factorial Program&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;pre class=&quot;prettyprint linenums:1&quot;&gt;#include&amp;nbsp;&amp;lt;stdio.h&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
This is a preprocessor directive.&lt;br /&gt;
Program execution starts with main()&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums:2&quot;&gt;int&amp;nbsp;main()
&lt;/pre&gt;
&lt;br /&gt;
We initialize three integer variables, namely &#39;n&#39;, &#39;i&#39; and &#39;fac&#39;, and give an initial value of 1 to fac. The variable n holds the number that is input by the user. The variable &#39;i&#39; acts as the loop counter.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint linenums:6&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for(i=1;i&amp;lt;=n;i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fac&amp;nbsp;=&amp;nbsp;fac&amp;nbsp;*&amp;nbsp;i;
&lt;/pre&gt;
&lt;br /&gt;
Thus, the for loop initializes &#39;i&#39; to 1, then checks if &#39;i&#39; is less than or equal to &#39;n&#39;. If condition is true, then the statement gets executed and &#39;i&#39; is incremented by 1. Thus, the loop carries out the statement &#39;n&#39; number of times.&lt;/div&gt;
</description><link>http://csimpleprograms.blogspot.com/2013/06/blog-post_21.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmZSGJ0EXcTLFZUuBS5axJukcgnXxfRJwDanfARgKig4mBtk22c4EiQnDPciHz4k8e57B7RrmvwxnVmgalUqVso42EdsOhk5cCglki77zT9L-8m7vUgr5FFmkn4jI2XNWsaizwW7sdaD1h/s72-c/c-language-factorial-output.JPG" height="72" width="72"/></item></channel></rss>