Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the code for num_sum.c: #include void num_sum(int n, int *num, int *sum); //declaration of function void num_sum(int n, int *num, int *sum) {

image text in transcribed

Here is the code for num_sum.c:

#include

void num_sum(int n, int *num, int *sum); //declaration of function

void num_sum(int n, int *num, int *sum) { while (n > 0) //repeating number n until it is 0 { *num += 1; //incrementing # of digits *sum += n%10; //calculating sum of individual digits n /= 10; } }

int main(void) { //variables int n; int sum = 0, num = 0; //prompt user for number input printf("Enter a positive integer: "); scanf("%d", &n); //calling num_sum function into main num_sum(n, &num, &sum); //output results printf("The number has %d digit(s), sum of which is %d ", num, sum); return 0; }

EXTRA CREDIT (10 points) In order to understand recursion, you must first understand recursion" - found somewhere on the Internet. Trying Googling "recursion", this search is one of fun Easter eggs of Google search like searching "do a barrel roll". Can you reimplement your function, num_sum ), such that it is a recursive function Name you file num.sum rec.e. Example executions: $ gc-Wallonum_sum_rec num_sum_rec. .um_sum_rec Enter a positive integer: 5 The number has 1 digit (s), sum of which is 5 . / num rec

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions

Question

=+How might these stem from country and regional cultures?

Answered: 1 week ago