Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:35:03+00:00 2026-05-23T16:35:03+00:00

Trying to achieve something like this using recursion: if (m > n) return; Foo

  • 0

Trying to achieve something like this using recursion:

if (m > n) return;
Foo 1          // no tabs
   Foo 2       // \t
      Foo 3    // \t\t
   Foo 2       // \t
Foo 1          // no tabs

I have a function that takes 2 parameters: void indent(int m, int n);
(calling number from m to n).

So far I figured this much out:

  • As long as m <= n, keep calling the function. (base case)
  • Print the first line without any tabs setw(0)
  • Call the function recursively with m+1 increment. setw(4*m)
  • Print the first line without any tabs (again). setw(0)

Am I on the right track? Is my pseudocode correct at least?

Also, is there any way to express tabs numerically? I can’t think of any way to use tab \t using either recursion or iteration.

Update: I figured it out :). cout << setw(4*m); right before cout << "Foo"; does the trick. On first call m=0 so setw(0), on 2nd call setw(4), then setw(8) and so on. Now I just have to print the text backward to 0 tabs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:35:04+00:00Added an answer on May 23, 2026 at 4:35 pm

    Looks like you are on the right path. You would just want your recursive method to check when m == n, you would only print the line once rather then twice and then unroll.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server 2005 and I'm trying to achieve something like this: I
I've trying to achieve something like this: class Base { public: Base(string S) {
What I am trying to achieve is something like this: class object: def __init__(self):
I am trying to achieve something like the follwing: This is a WPF Flow
I'm trying to get something like this working: function posts_formatter (&$posts){ foreach ($posts as
I am trying to achieve something like this with CSS: I'd like to keep
Something like this is what Im trying to achieve: public Attribute<?> getAttribute(Class<? extends Attribute>
ok so this is what I am trying to achieve is to have two
I'm trying to achieve table similar to this using css/html only. Is it possible
I trying to achieve something like as below :- <%= link_to <%= user.email %>,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.