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

You might know about ABRACADABRA — it is a magic word usually used in stage magi

ID: 3909756 • Letter: Y

Question

You might know about ABRACADABRA — it is a magic word usually used in stage magic tricks, and historically was believed to have healing powers when inscribed on an amulet. In order for writing to have the powers ascribed to it, it needed to be written as shown below (note a single space between the consecutive letters in the word): A B R A C A D A B R A A B R A C A D A B R A B R A C A D A B A B R A C A D A A B R A C A D A B R A C A A B R A C A B R A A B R A B A (like pyramid but inverse, last letter A is in the bottom) Let’s say you’re a new-age entrepreneur who makes up new magic words to print them on shirts, bracelets, etc. Your task is to implement the function (only the function) that prints this format given the string magic word. In the example above, magic word=’’ABRACADABRA’’ (no spaces.)

Explanation / Answer

#include<iostream>
using namespace std;
void display(string d){
    int a = 0;
    int b = d.length() - 1;
  
    while(b >= 0){
        for (int i = 0; i<=b; i++){
           cout << d[i] << " ";
        }
        cout << endl;
        b--;
    }
}

int main(){
   string str ="ABRACADABRA";
   display(str);
   return 0;
}

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