Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, you will write two recursive functions, both of which will

ID: 3935860 • Letter: F

Question

For this assignment, you will write two recursive functions, both of which will parse any length string that consists of digits and numbers. Both functions should be in the same class and have the following signatures. Make sure you follow the UML exactly, as I will be running unit tests on your submission using this interface.

Write a recursive function that will add up the digits in the string. Example inputs and results:

2. Write a recursive function that will find the largest integer in this string.

input string result "1d2d3d" 6 "55" 10 "xx" 0

Explanation / Answer

Answer:

Q. 1 Write a recursive function that will add up the digits in the string. Example inputs and results:

Answer:

#include<ctype.h>

int sum;

// char str[]="p13d3f";

void fun()

{

char ch;

scanf("%c", &ch);

if (isdigit(ch))

{

sum += ch - '0';

}

if (ch != ' ')

{

fun();

}

}

main()

{

printf("String.. ");

fun();

printf("Sum=%d", sum);

}

Q Write a recursive function that will find the largest integer in this string.

Answer:

#include<stdio.h>

#include<ctype.h>

int num,

large;

void fun()

{

char ch;

ch = getchar();

if (isdigit(ch))

{

num = ch - '0';

ch = getchar();

while (isdigit(ch))

{

num = num * 10 + ch - '0';

ch = getchar();

}

if (large <= num)

{

large = num;

}

}

if (ch != ' ')

fun();

}

main()

{

printf("Enter the string: ");

fun();

printf("largest value=%d", large);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote