{"id":4049,"date":"2022-11-09T14:58:26","date_gmt":"2022-11-09T14:58:26","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=4049"},"modified":"2022-11-09T14:58:28","modified_gmt":"2022-11-09T14:58:28","slug":"c-program-to-find-square-of-a-number","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/c-program-to-find-square-of-a-number\/","title":{"rendered":"C Program to Find Square of a Number"},"content":{"rendered":"<p style=\"text-align: center;\"><strong>C Program to Find Square of a Number<\/strong><\/p>\n<p>In this article, we are going to discuss how to calculate the square of a number.<\/p>\n<p>For example &#8211;<\/p>\n<p>Input-<br \/>\nthe first step we take user input in this program so for that we take suppose 22.<\/p>\n<p>Logic &#8211;<br \/>\nTo calculate the square of a given number we required the formula and the formula is :<br \/>\nsquare = number * number;<\/p>\n<p>Output &#8211;<br \/>\nAccording to our input, we get output as<\/p>\n<p>Enter the number:22<br \/>\nThe square of 22.000000 is: 484.000000<\/p>\n<p>So let&#8217;s start to implement these given formulas in our program.<\/p>\n<p>\/\/C program to calculate the square of number<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\nint main()<br \/>\n{<br \/>\nfloat number, square;<br \/>\nprintf(&#8220;Enter the number :&#8221;);<br \/>\nscanf(&#8220;%f&#8221;, &amp;number);<br \/>\nsquare = number * number;<br \/>\nprintf(&#8220;The square of %f is : %f&#8221;, number, square);<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>output<\/p>\n<p>Enter the number:22<br \/>\nThe square of 22.000000 is: 484.000000<\/p>\n<p>From the above program, we can see that, by using a formula we simply calculate the square of a number. But now we are going to calculate the square of numbers by using user define a function, so let&#8217;s start.<\/p>\n<p>\/\/C program to calculate the square of the number<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\nfloat square(float number){<br \/>\nreturn number * number;<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\nfloat number;<br \/>\nprintf(&#8220;Enter the number :&#8221;);<br \/>\nscanf(&#8220;%f&#8221;, &amp;number);<br \/>\nprintf(&#8220;The square of a number is : %f&#8221;,square(number));<br \/>\nreturn 0;<br \/>\n}<br \/>\nOutput<\/p>\n<p>Enter the number:12<br \/>\nThe square of a number is: 144.000000<\/p>\n<p>From the above program, we can see that in this program we simply use the user to define a function in it.<\/p>\n<p>By using these functions we simply return the output of our by using these function.<\/p>\n<p>So these are the two methods, by using these we can simply calculate the square of any number. I hope these methods understand you. You can also explore these programs by using another value. So for now keep learning, and keep exploring!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C Program to Find Square of a Number In this article, we are going to discuss how to calculate the square of a number. For example &#8211; Input- the first step we take user input in this program so for that we take suppose 22. Logic &#8211; To calculate the square of a given number [&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],"class_list":{"0":"post-4049","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-c-program","7":"tag-c-program"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4049","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=4049"}],"version-history":[{"count":1,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4049\/revisions"}],"predecessor-version":[{"id":4050,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4049\/revisions\/4050"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=4049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=4049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=4049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}