Answer:
#include <iostream>
#include <cstring>
using namespace std;
bool isAPalindrome(char* palindrome);
int main()
{
char palindrome[30];
bool palindrome_check;
cout << "Please enter an word or phrase.\n";
cin.getline(palindrome, 30);
palindrome_check = isAPalindrome(palindrome);
if (palindrome_check = true)
{
cout << "Input is a palindrome\n";
}
else
{
cout << "Inputis not a palindrome\n;";
}
system("pause");
return 0;
}
bool isAPalindrome(char* palindrome)
{
char* front;
char* rear;
front = palindrome;// starts at the left side of the c string
rear = (palindrome + strlen(palindrome)) - 1;//starts at the right side of the c-string. adds the c string plus the incriment value of s
while (front <= rear)
{
if (front = rear)
{
front++;
rear--;
}
else
{
return false;
}
}
return true;
}
Answer:
public static int sumStrings(String s1, String s2, String s3) {
int i1 = Integer.parseInt(s1);
int i2 = Integer.parseInt(s2);
int i3 = Integer.parseInt(s3);
int sum = i1 + i2 + i3;
return sum;
}
Explanation:
- Create a method called <em>sumStrings</em> that takes three strings
- Convert each string to integer using Integer.parseInt() method
- Sum the strings
- Return the result
Answer:
a[i] = a[len(a) - i - 1]
Explanation:
Based on the definition of corresponding elements above,
First element of a list and last element are corresponding :
Using this :
Given a list defined as 'a'
First element of list is at index 0
Last element of a list is at index ; len(a) - 1
For a list containing 10 elements:
Second element corresponds to second to the last element
Second element is at index 1;
Second to the Last element is at index 8
(since indexing starts from 0)
Second element = a[1]
Second to the last element = a[len(a) - i - 1]
Hence,
a[i] = a[len(a) - i - 1]