{"id":4635,"date":"2023-01-23T12:09:05","date_gmt":"2023-01-23T12:09:05","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=4635"},"modified":"2023-01-23T12:09:06","modified_gmt":"2023-01-23T12:09:06","slug":"c-program-to-find-last-digit-of-a-number","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/c-program-to-find-last-digit-of-a-number\/","title":{"rendered":"C Program to Find Last Digit Of a Number"},"content":{"rendered":"\n<p>In this article, we are going to discuss how to get the last digit from a given number. So basically if we want the last digit of a given number then we have to divide that number by 10 after that we get a remainder and that remainder is our final answer means that the remainder is our last digit.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C Program to Find Last Digit Of a Number<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">For example-<\/h4>\n\n\n\n<p><strong>Input-<\/strong><\/p>\n\n\n\n<p>So first step we are going to take input from the user in the form of the number, suppose we take 22456.<\/p>\n\n\n\n<p><strong>Logic-<\/strong><\/p>\n\n\n\n<p>So to calculate the last digit of a given number we required the formula that is :<br>last_digit = number % 10<\/p>\n\n\n\n<p><strong>Output-<\/strong><\/p>\n\n\n\n<p>according to our input, we get output as<br>Enter the number:22456<br>The last digit of 22456 is 6<\/p>\n\n\n\n<p>So let&#8217;s try to implement these formulas in our program, so let&#8217;s start!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Method 1:<\/h4>\n\n\n\n<p>\/\/ get the last digit from the given number<\/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>{<br>int num, last_digit;<br>printf(&#8220;Enter the number :&#8221;);<br>scanf(&#8220;%d&#8221;,&amp;num);<br>last_digit = num % 10;<br>printf(&#8220;The last digit of %d is %d&#8221;,num, last_digit);<br>return 0;<br>}<\/p>\n\n\n\n<p><strong>Output-<\/strong><\/p>\n\n\n\n<p>Enter the number:22456<br>The last digit of 22456 is 6<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Method 2:<\/h4>\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 last_digit(int num){<br>return (num%10);<br>}<br>int main()<br>{<br>int num;<br>printf(&#8220;Enter the number :&#8221;);<br>scanf(&#8220;%d&#8221;,&amp;num);<br>printf(&#8220;The last digit of given number is %d&#8221;, last_digit(num));<br>return 0;<br>}<\/p>\n\n\n\n<p><strong>Output-<\/strong><\/p>\n\n\n\n<p>Enter the number:12345354<br>The last digit of a given number is 4<\/p>\n\n\n\n<p>From the above program, we can see that,<\/p>\n\n\n\n<p>we simply use user define a function in it. <\/p>\n\n\n\n<p>In that we give the last_digit name to the function after that we simply pass the value of the number in the parameters and then we simply apply the formula.<\/p>\n\n\n\n<p>then after that, we simply use the main function.<\/p>\n\n\n\n<p>So these are the two methods to find the last digit of the given number, I hope these concepts are clear to you now, you can explore this concept by putting new values in it. 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 get the last digit from a given number. So basically if we want the last digit of a given number then we have to divide that number by 10 after that we get a remainder and that remainder is our final answer means that the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-4635","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-uncategorized"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4635","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=4635"}],"version-history":[{"count":1,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4635\/revisions"}],"predecessor-version":[{"id":4636,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/4635\/revisions\/4636"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=4635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=4635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=4635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}