Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2) Number of digits and sum of digits of an input positive integer (50 points) Write a C program. num-sum. c, to ask the user

image text in transcribed

2) Number of digits and sum of digits of an input positive integer (50 points) Write a C program. num-sum. c, to ask the user for a positive integer number (assume that the input is greater than 0). Your program must print out the number of digits and sum of the digits For example, if the user inputs 1991, you should output something like "The number has 4 digit(s), sum of which is 20". The calculations must happen in a function called num _sum () which has the following declaration void num sum(int n, int *num, int sum); Your program must: 1. Implement the above function where all the calculations happen. Notice that we need two values from the calculations, but C functions can return only a single value. Thus we use pointers in the parameter of num_sum () function (pass by reference) to modify the original arguments and does not require us to return any value. 2. The main() function must ask user for a positive integer, call num sum ) function, and then display/print the result Example executions: $ $ gcc-Wall1 -o num sum num sum.c $ . um sunm Enter a positive integer: 1991 The number has 4 digit (s), sum of which is 20 $ . um sum Enter a positive intege 109982 The number has 6 digit (s), sum of which is 29 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.c. Example executions: $ gcc -Wall -o num sum rec num sum rec.c $ . um sum rec Enter a positive integer: 5 The number has l digit(s), sum of which 1s 5

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_2

Step: 3

blur-text-image_3

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

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions