{"id":81,"date":"2021-09-20T12:37:00","date_gmt":"2021-09-20T12:37:00","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=81"},"modified":"2021-10-11T11:52:22","modified_gmt":"2021-10-11T11:52:22","slug":"sum-of-digits-in-c-using-recursive-function","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/sum-of-digits-in-c-using-recursive-function\/","title":{"rendered":"C Program for Sum of digits using recursive function"},"content":{"rendered":"\n<p>Below program first accept the positive number from user and then find out the sum of digits. for example if user enter 234 then sum of digit is 2+3+4 = 9<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Program Name: Write a function for Sum Of digits\n\/\/ for example if user enter 121 then sum of digit is 1+2+1 = 4\n\n#include&lt;stdio.h&gt;\n#include&lt;conio.h&gt;\nint sum_d(int n)\n {\n    if(n==0)\n       return(0);\n    else\n      return(n%10+sum_d(n\/10));\n }\/\/end of function\n\nvoid main()\n{     int no,sum;\n\n      printf(\"\\n\\tEnter a number to calculate digit sum:\\t \");\n      scanf(\"%d\",&amp;no);\n\n       sum=sum_d(no);\n\n      printf(\" \\n\\n\\tSum of digit is =\\t %d \",sum);\n\n}\/\/end of main<\/code><\/pre>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<div class=\"wp-block-columns has-white-color has-cyan-bluish-gray-background-color has-text-color has-background is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>\n        Enter a number to calculate digit sum:   543\n \n\n        Sum of digit is =        12\n\n\n        Enter a number to calculate digit sum:   2\n \n\n        Sum of digit is =        2\n\n\n\n<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Below program first accept the positive number from user and then find out the sum of digits. for example if user enter 234 then sum of digit is 2+3+4 = 9 Output<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-c-language"],"aioseo_notices":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"sparkling-featured":false,"sparkling-featured-fullwidth":false,"tab-small":false},"uagb_author_info":{"display_name":"program45_-rt8nb","author_link":"https:\/\/ethosspace.com\/programmers\/author\/program45_-rt8nb\/"},"uagb_comment_info":0,"uagb_excerpt":"Below program first accept the positive number from user and then find out the sum of digits. for example if user enter 234 then sum of digit is 2+3+4 = 9 Output","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":3,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":277,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/81\/revisions\/277"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}