FOR C PROGRAMMING LANGUAGE
Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const char* str2) which returns the sum of strlen(str1) and strlen(str2). You can assume that strlen(str2) is always strictly greater than strlen(str1) (strlen(str2) > strlen(str1)). You MAY NOT use any function from string.h. You MAY NOT use any square brackets([]) or any type of loops in function.
#include <stdio.h> int sumStrlens(const char *str1, const char *str2); int main() { printf("%d\n", sumStrlens("Hello", "How are you?")); return 0; } int sumStrlens(const char *str1, const char *str2) { if (!(*str1)) { if (!(*str2)) { return 0; } else { return 1 + sumStrlens(str1, str2 + 1); } } else { return 1 + sumStrlens(str1 + 1, str2); } }
Get Answers For Free
Most questions answered within 1 hours.