Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a C program a) Write an int function countDigits(int x, int d) that counts the number of times that the digit d occurs in

write a C program

a) Write an int function countDigits(int x, int d) that counts the number of times that the digit d occurs in the integer x. That is, countDigits(12323, 2) would return 2 and countDigits(12323, 1) would return 1. You may assume that d is a number in the range 0..9 inclusive and that x is positive. countDigits(0,0) is 1. Hint: Be careful in coding when d is 0. countDigits(10,0) is 1.

(b) Write a unit test function testCountDigits(int x, int d, int result, char *msg) that calls countDigits(x,d) and compares the result with 'result', and prints out 'test passed' followed by the message msg if these values agree and 'test failed' followed by the message msg otherwise.

(c) Write a main function that executes your unit test functions and at lest calls

testCountDigits(123, 1, 1, "single digit test");

testCountDigits(10, 0, 1, "single 0 test");

testCountDigits(456456, 4, 2, "two fours");

testCountDigits(111111, 1, 6, "six 1's");

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

Under what conditions will a firm shut down temporarily? Explain.

Answered: 1 week ago

Question

Lo6 Identify several management development methods.

Answered: 1 week ago

Question

LO4 List options for development needs analyses.

Answered: 1 week ago