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 7794723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:51:28+00:00 2026-06-01T22:51:28+00:00

I want to create a 2nd array using a function; the user will enter

  • 0

I want to create a 2nd array using a function; the user will enter the dimensions(x,y) and the function will print it; in the first row must appear the numbers 1,2,3…x and in the first column the characters a,b,c,d,e….y(y is given as a number).

For example if the user enters x=5 y=7 it will print:

  1 2 3 4 5 
a _ _ _ _ _
b _ _ _ _ _
c _ _ _ _ _
d _ _ _ _ _
f _ _ _ _ _
h _ _ _ _ _
i _ _ _ _ _

I wrote some code but I don’t know how to do this with the letters.

void function(int x,int y)
{ 
    char th[x][y];

    for (int i = 1; i < x; i++)
    { 
       for (int j = 1; j < y; j++)
       {
          if(i==1 )
          {
            for (int k = 1; k < x; k++)
            {
               th[i][j]=k;
            }
          }
          else if(j==1)
          {
            th[i][j]='a';
          }
          else
          {
            th[i][j]='_';
          }
          std:: cout << th[i][j] <<'\t';
       }

       cout << std::endl;
    }  
 }
  • 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-01T22:51:30+00:00Added an answer on June 1, 2026 at 10:51 pm

    Use the character code representations and the fact that ‘b’ == ‘a’ + 1 (and so forth).

    If you have a zero-based index I, and you want to convert that to letters, it really is as easy as printing ‘a’ + I. If you want it in caps, print ‘A’ + I.

    Also note that you can really simplify those loops. There’s no reason to have three loops nested. You need a single for loop for the first row (generating the numeric column headers), and then a doubly-nested for-loop for the remaining rows. Something like the following (completely untested) code:

    // print header
    std::cout << ' ';
    for (int i = 0; i != x; ++i)
      std::cout << ' ' << i;
    std::cout << '\n';
    
    // print body
    for (int j = 0; j != y; ++j)
    {
      // column leader
      std::cout << char('a' + j);
    
      // column body
      for (int i = 0; i != x; ++i)
        std::cout << " _";
      std::cout << "\n";
    }
    

    Following up on your desire to have data in cells, you need to allocate space for them. if you have X columns by Y rows, you need X*Y cells. You can index these by using X*j+i, where i,j is the column,row you want to access. Something like:

    std::vector<int> cells(x * y);
    
    // inside the loop, in place of printing " _", use:
    std::cout << ' ' << cells(x * j + i);
    

    If you want to keep the underscore for “empty” values, you need to pick some integer to represent a nil value (zero, negative, INT_MAX, whatever) and fill the vector with that. Then put in an if condition to print the underscore if the cell value is the nil value, and print the cell value directly otherwise.

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

Sidebar

Related Questions

I want to create a program that will take user input and create a
want to create listview with 2 component in every row 1st progressbar and 2nd
I want to create an app for iPod Touch 2nd generation (iOS 4.2.1). For
I want create a excel with Apache POI in java and I must insert
I want to create 5 variables of type array all at once. Is this
A user can create an object, and he has followers that I want to
I want to create 2 multiselect side by side. The first one is populated,
I want create a drop shadow around the canvas component in flex. Technically speaking
i want create image animation , i have 50 images with png format now
I want create module which update list of usb devices automatically (not only mass

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.