Question

how do i make a code that reads a sentence from both sides (using for loops)....

how do i make a code that reads a sentence from both sides (using for loops). This is for a palindrome.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In order to do so, you would need to maintain two loop variables, one that reads from the start of the sentence to the middle of the sentence, and one that would read from the end of the sentence to the middle of the sentence. The sample for loop is shown below.

Let us assume that n is the length of the sentence.

for (int i=0, j = n-1; i<n/2; i++, j--) {

}

Add a comment
Know the answer?
Add Answer to:
how do i make a code that reads a sentence from both sides (using for loops)....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How do I create a simple java program file that opens and reads a file using...

    How do I create a simple java program file that opens and reads a file using java.io? I have the file Im supposed to open and read but I dont know how to code it to open and read the file?

  • How do I write a java code that mimics charAt without using java API just primitives...

    How do I write a java code that mimics charAt without using java API just primitives and no charAt to be used? I know it comes from primitives but I am confused on how to assemble the loops to derive my own charAt code

  • USING ONLY LOOPS CANNOT USE INDEXING OF STRINGS (STR) PYTHON 3 CODE IS TESTED WITH JDK...

    USING ONLY LOOPS CANNOT USE INDEXING OF STRINGS (STR) PYTHON 3 CODE IS TESTED WITH JDK AND WILL KNOW WHEN USING FORBIDDEN CODE write a program called reversibleSentence -- ask for a word from user -- if word is the same read from left to right or right to left, then -- print "the word is reversible", else -- print "the word IS NOT reversible" HINT: The following program prints heo sentence = "" for x in "hello": if x...

  • How do implement this function using a multiplexer? How do I make a truth table from...

    How do implement this function using a multiplexer? How do I make a truth table from a function? How do I implement the function F(Wixiyiz )=E(0121416) using a multiplexer??

  • A palindrome is a word or phrase that reads the same both forwards and backwards. "racecar"...

    A palindrome is a word or phrase that reads the same both forwards and backwards. "racecar" is a palindrome. So is, "a man a plan a canal, panama" if you ignore the spacing and the comma. Discovering how to automate the detection of palindromes is a good way to test your understanding of loops and strings. The file, "hw2problem5.py", contains a function called is_palindrome(), which has a single string parameter, s. If s is a palindrome, then is_palindrome() returns the...

  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...

  • A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here...

    A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for the user input....

  • Write a program that reads a sentence input from the user. The program should count the...

    Write a program that reads a sentence input from the user. The program should count the number of vowels(a,e,i,o,u) in a sentence. Use the following function to read the sentence. Should use switch statement with toupper. int read_line(char str[],int n) {    int ch, i=0;    while((ch =getchar()) != '\n')        if(1<n)            str[i++]==ch;    str[i] != '\0';    return i; } output should look like: Enter a sentence: and thats the way it is! Your sentence...

  • Using Visual Studio 2017 Create This Program Using C# implement source code Program 5: The concept...

    Using Visual Studio 2017 Create This Program Using C# implement source code Program 5: The concept of a 5-digit palindrome number is a 5-digit number that reads the same from left to right and from right to left. For example, 12121, 45454, and 14741 are valid 5-digit palindrome numbers. Design (pseudocode) and implement (source code) a program (name it FiveDigitPalindrom) that reads a 5-digit number from the user (as integer value, not string) and then mathematically (using division and remainder...

  • How do I solve #43 In Problems 43-46, multiply both sides of the equa- tion by...

    How do I solve #43 In Problems 43-46, multiply both sides of the equa- tion by the LCD and solve the resulting quadratic equation. 8 3 43. x + - 9 44. x-2 x + 1 х х

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT