1. DOES A DIGIT APPEAR IN AN INTEGER, Write a recursive function appears(n,i) that returns true if the digit i appears in the positive (base 10) integer n, false if it does not in c++. ex.
Enter a positive integer: 54321 Enter a digit: 7 The digit 7 does NOT appear in the integer 54321.
2. IS AN INPUT STRING A PALINDROME? A palindrome is a string in which the letters are the same in both directions, disregarding capitalization and non-letter characters. Write a program that reads a sequence of characters and calls a recursive Boolean function to determine if the letters in the string form a palindrome in c++. example:
csh> pal Enter a line that might be a palindrome: Madam I'm Adam. This string IS a palindrome.
1)
#include <bits/stdc++.h>
using namespace std;
bool appears(int n, int i)
{
// Base case
if(n < 10)
{
return (n == i);
}
// If last digit is i return true
if(n%10 == i)
return true;
// Else recur for n/10
return appears(n/10, i);
}
int main()
{
cout << "3 appears in 1234: " << appears(1234, 3) << " 6 appears in 1234: " << appears(1234, 6);
return 0;
}
Output :
2)
#include <bits/stdc++.h>
using namespace std;
bool palindrome(char str[], int s, int e)
{
// Base case
if(s == e || s + 1 == e)
return true;
// If start is special character then increment s
while((str[s] < 'a' || str[s] > 'z') && (str[s] < 'A' || str[s] > 'Z'))
s++;
// If end is special character then decrement e
while((str[e - 1] < 'a' || str[e - 1] > 'z') && (str[e - 1] < 'A' || str[e - 1] > 'Z'))
e--;
// If start and last are unequal then return false
if(tolower(str[s]) != tolower(str[e - 1]))
return false;
// Otherwise recur
return palindrome(str, s + 1, e - 1);
}
int main()
{
char str[100];
cout << "Enter the string ";
cin >> str;
if(palindrome(str, 0, strlen(str)))
cout << "Palindrome ";
else
cout << "Not Palindrome ";
return 0;
}
Output:
Please upvote if satisfied!! Thanks :)
1. DOES A DIGIT APPEAR IN AN INTEGER, Write a recursive function appears(n,i) that returns true...
Write a recursive function Programming: to_number that forms the integer sum of all digit characters in a string. For example, the result of to_number("3ac4") would be 7. C++ i know this has been answered before but I keep getting 0 when I enter a string.
#19 with the following instructions 19. A palindrome is a string that can be read backward and forward with the same result. For example, the following is a palindrome: Able was I ere I saw Elba. unction to test if a string is a palindrome using a stack. You can push characters in the stack one by one. When you reach the en string, you can pop the characters and form a new string. If the two strings are exactly...
In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...
Write a recursive function named arithmeticSum that takes a positive integer parameter n and returns the sum of the integer numbers from 1 to n Please write in C++
Please i need programs in C 32) Write a function that, given a string, a width, and an empty string for output, centers the string in the output, centers the string in the output area. The function is to return 1 if the formating is successful and 0 if any errors, such as string length greater than width, are formed. 35) Write a function called newStrCmp that does the same job as strcmp. The declaration for your functions is to...
Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...
Does someone know how to solve this in java code? I'm taking programming level 1 Write a program that prompts the user to enter a three-digit integer and determines whether it is a palindrome number. A number is palindrome if it reads the same from right to left and from left to right.
I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...
Write c++ recursive function 3. A function that takes an integer, and returns the product of the digits, so the input 1989 would return 1∗9∗8∗9 = 648 4. A function that does the above repeatedly, taking a number and computing the product of it’s digits until you get a single digit number: so on input 1989 it would go 1989→648→192→18→8 and return 8. (Note, you can use the previous functions if you want.
For integer n € {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) function hex(n) returns hexadecimal character from F. Write function hex and use it to create the function HEX(N) that for integer N>0 displays its value hexadecimal form. For all programs use C++, and make all programs as short as possible. Write the main program that supports the following sample dialog: Enter a positive integer : 13 Hexadecimal value D Enter a positive integer : 255 Hexadecimal value Enter a positive integer ; 1234567 Hexadecimal value...