A function that calls another function, which in turn calls the original functio
ID: 3657679 • Letter: A
Question
A function that calls another function, which in turn calls the original function, is said to be corecursive. Note that corecursive functions occur in pairs. Write a program that counts the number of alphabetic characters in a string and sums the digits in the string. For example, the string "AOis444apple7" has eight alphabetic characters, and the digits in the string sum to 19. Write a pair of corecursive functions to help carry out the tasks. Use count_alph() to count the alphabetic characters, and use sum_digit() for summing the digits. These two functions should call each other. For comparison, write a non-corecursive function that performs the two tasks in a direct, more natural fashion. Hint: If necessary, use static variables.Explanation / Answer
#include #include #include int countAlpha(char *);// counts all alpha chars int sumDigits(char *);// finds digits and sums int main(void){ char s[]=("AOis444apple7"); //string being tested countAlpha(s);// calls string to alpha count } int countAlpha(char *s) { int i;//counter int countAlpha=0; for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.