{"id":4347,"date":"2022-12-15T12:40:04","date_gmt":"2022-12-15T12:40:04","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=4347"},"modified":"2022-12-15T12:40:05","modified_gmt":"2022-12-15T12:40:05","slug":"how-to-find-the-perimeter-of-a-square-in-c","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/how-to-find-the-perimeter-of-a-square-in-c\/","title":{"rendered":"How to find the perimeter of a square in C"},"content":{"rendered":"\n<p>In this article, we are going to discuss how to calculate the perimeter of the square. So let&#8217;s start.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to find the Perimeter of a square in C<\/h2>\n\n\n\n<p><strong>For example-<\/strong><\/p>\n\n\n\n<p>Input &#8211;<br>So first step is we are going to take input from the user in the form of the side that is 2<\/p>\n\n\n\n<p><strong>Logic &#8211;<\/strong><\/p>\n\n\n\n<p>To calculate the perimeter of a square we have to know about the formula first, So the formula is : <br>Perimeter = 4 * side<\/p>\n\n\n\n<p><strong>Output-<\/strong><br>according to our input, we get the output as follows:<\/p>\n\n\n\n<p>Enter the side of square:4<br>the perimeter of a square is 16.000000<\/p>\n\n\n\n<p>We are going to see two examples to calculate the perimeter of a square one by using a simple formula and another one by using a user-defined function.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<p>\/\/C program to find the perimeter of the square<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">#include&lt;stdio.h&gt;<br>int main(){<br>float = side, perimeter;<br>printf(&#8220;Enter the side of square :&#8221;);<br>scanf(&#8220;%f&#8221;, &amp;side);<br>perimeter = 4 * side;<br>printf(&#8220;The perimeter of a square is %f&#8221; , perimeter);<br>return<br>}<\/p>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<p>Enter the side of square:4<br>The perimeter of a square is 16.000000<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> First we take two float-type variables first one is to take the side of the square from the user and the second one is to print the value in the perimeter.<\/p>\n\n\n\n<p><strong>Step 2:<\/strong> After that, we simply use scanf() to store the value of a variable.<\/p>\n\n\n\n<p><strong>Step 3:<\/strong> then we simply use the formula to calculate the perimeter. We can see that we simply use the perimeter variable to calculate the perimeter.<\/p>\n\n\n\n<p><strong>Step 4:<\/strong> after all these steps we simply use printf() to get our final answer.<\/p>\n\n\n\n<p><strong>Example 2 :<\/strong><\/p>\n\n\n\n<p>\/\/ C program to calculate the perimeter of a square by using a user-defined function.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">#include&lt;stdio.h&gt;<br>float perimeter(float side){<br>return 4 *side;<br>}<br>int main(){<br>float side, p;<br>printf(&#8220;Enter the side of square :&#8221;);<br>scanf(&#8220;%f&#8221;, &amp;side);<br>p = perimeter(side);<br>printf(&#8220;The perimeter of a square is %f&#8221;, p);<br>return 0;<br>}<\/p>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<p>Enter the side of square:16<\/p>\n\n\n\n<p>The perimeter of a square is 64.000000<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> First we create a user-defined function. From the above example, we can see that we create a user-defined function that gives a name as the perimeter and use the float type parameter in it and gives a name as the side.<\/p>\n\n\n\n<p><strong>Step 2:<\/strong> then we go to the main function. In that we take two float-type variables first one is to take the side of the square from the user and the second one is to print the value that is p.<\/p>\n\n\n\n<p><strong>Step 2:<\/strong> After that, we simply use scanf() to store the value of a variable.<\/p>\n\n\n\n<p><strong>Step 3:<\/strong> Then we pass the value in variable p . from the above program, we can simply see that we pass the value in p.<\/p>\n\n\n\n<p><strong>Step 4:<\/strong> after all these steps we simply use printf() to get our final answer.<\/p>\n\n\n\n<p>In this way, we simply understand how to calculate the perimeter of the square. I hope you simply understand this program. So for now keep learning and keep exploring.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to discuss how to calculate the perimeter of the square. So let&#8217;s start. How to find the Perimeter of a square in C For example- Input &#8211;So first step is we are going to take input from the user in the form of the side that is 2 Logic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[29,53],"class_list":{"0":"post-4347","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-c-program","7":"tag-c-program","8":"tag-how-to-find-the-perimeter-of-a-square-in-c"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=4347"}],"version-history":[{"count":1,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4347\/revisions"}],"predecessor-version":[{"id":4348,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4347\/revisions\/4348"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=4347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=4347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=4347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}