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

  • SEARCH
  • Home
  • 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 8092371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:16:12+00:00 2026-06-05T20:16:12+00:00

I’m trying to write a code that could print something like this -xv -xvv

  • 0

I’m trying to write a code that could print something like this

-xv
-xvv
-xvvv
-xvvvv
-xvvvvv

-xxv
-xxvv
-xxvvv
-xxvvvv
-xxvvvvv

-xxxv
-xxxvv
-xxxvvv
-xxxvvvv
-xxxvvvvv

The extra spacing between the 3 “groups” are just for clarity’s sake. The maximum number of ‘-‘ is 1, ‘x’ is 3, ‘v’ is 5, and the number of each symbol increments.

To draw this diagram, I have the following code

for (k = 1 ; k <= num_dash ; k++)
{
   for (i = 1 ; i <= num_x ; i++)
   {
      for (j = 1 ; j <= num_v ; j+++)
      {
         for (k1 = 0 ; k1 < k ; k++)
            printf("-");
         for (i1 = 0 ; i1 < i ; i++)
            printf("x");
         for (j1 = 0 ; j1 < j ; j++)
            printf("v");
         printf("\n");
      }
   }
}

This is when I know there are 3 different kinds of symbols. Is it possible to do the same if the number of symbols are only known at runtime? For example, what if I want the same program to also be able to print

xv
xvv
xvvv
xvvvv
xvvvvv

xxv
xxvv
xxvvv
xxvvvv
xxvvvvv

xxxv
xxxvv
xxxvvv
xxxvvvv
xxxvvvvv

In this case, my code would only be

   for (i = 1 ; i <= num_x ; i++)
   {
      for (j = 1 ; j <= num_v ; j+++)
      {
         for (i1 = 0 ; i1 < i ; i++)
            printf("x");
         for (j1 = 0 ; j1 < j ; j++)
            printf("v");
         printf("\n");
      }
   }

And there are only 2 for-loops instead of 3. Can I write my code such that the number of for-loops varies?

  • 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-06-05T20:16:13+00:00Added an answer on June 5, 2026 at 8:16 pm

    E.g.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void print_aux(char **symbols, int *times, int len, int pos, char *acc){
        int i;
        char *p;
    
        if(pos == len){
            printf("%s\n", acc);
            return;
        }
        p = malloc(sizeof(char)*strlen(symbols[pos])*times[pos]+strlen(acc)+1);
        for(i=0;i<times[pos];++i){
            int j;
            *p='\0';
            strcpy(p, acc);
            for(j=0;j<=i;++j){
                strcat(p, symbols[pos]);
            }
            print_aux(symbols, times, len, pos + 1, p);
        }
        if(pos + 1 == len)// when last symbol
            printf("\n",pos);
        free(p);
    }
    
    //wrap function
    void print(char **symbols, int *times, int len){
        print_aux(symbols, times, len, 0, "");
    }
    
    int main() {
        int i,n;
        char **symbols;
        int  *times;
    
        fprintf(stderr,"number of symbols :");
        scanf("%d", &n);
        symbols=(char**)malloc(sizeof(char*)*n);
        times = (int*)malloc(sizeof(int)*n);
        for(i=0;i<n;++i){
            char wk[128];
            fprintf(stderr,"input symbol [%d]:", i+1);
            scanf(" %s", wk);
            symbols[i] = strdup(wk);
            fprintf(stderr,"maximum number of \"%s\":",wk);
            scanf(" %d", &times[i]);
        }
    
        print(symbols, times, n);
    
        {   //release the allocated area
            for(i=0;i<n;++i){
                free(symbols[i]);
            }
            free(symbols);
            free(times);
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

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.