# Creating a Table for n, sqrt n and ln n from 0 to nmax

• stevenviney
In summary, the conversation is about a program that sets up a table displaying values of n, sqrt n, and ln n from n = 0 to a user-specified maximum integer nmax. The program prompts the user to enter a value for nmax and then attempts to display the table, but only outputs the memory address for the array. The conversation also discusses potential solutions for properly displaying the table, including using a spreadsheet program or manually printing each entry in the array. The idea of writing a function to print tables is also mentioned.
stevenviney
i need to write a program that sets up a table displaying values of n, sqrt n and ln n from n = 0 - nmax. I've prompted the user to enter a value for integer nmax. but then I've no idea how to make this apply for the value for nmax for my table.

this is what i have so far

Code:
//Problem Sheet 2 Table
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
const int numRows = n;
const int numColumns = 3;
double table[numRows][numColumns];
cout <<"This program will setup a table with values up to an integer n. Please enter your desired maximum integer n:"<< endl;
cin >> n;

cout <<table;

return 0;
}

how can i make nmax apply to the n i choose? and how can I set it up in a table which is displayed? I've spent hours and hours, I am sorry, I am so bad at this...

all i get out is 0x22cbd...

Do you specifically need to store the values in an array?
If you only have to write them out onto the screen then there is no need for an array...

I don't think "cout <<table;" is what you want (after you've built your table). You would want to loop through all of the elements in the array and send them (as scalars) to the stream... rather than sending the pointer to the table.

To build your table, you'd probably set up a for-loop from 0 to n and then calculate your values and place them in the table. As jpr0 mentioned, you may be able to skip the array altogether by immediately printing out the calculations for a particular value of i (0<=i<=n).

hmm..

no i do need an array becaue i need to list all the values from 0 - n so i assumed it would needed to be displayed in table form?

For what you are doing a spreadsheet program should suffice. OpenOffice.org Calc would do the trick or if you prefer M\$ then Excel.

Internally, an array is just a pointer. So when you say:

cout << table;

it prints the memory address where the array begins. As the others have said, you need to "manually" print each entry in the table.

Actually, if you're feeling up to it, you could write a function that takes a 2-dimensional array, as well as its dimensions, and does the printing... and then you could use that in the future when you want to print tables. (there will be some tricky language issues, though)

## 1. What is the purpose of creating a table for n, sqrt n and ln n from 0 to nmax?

The purpose of creating this table is to visualize the relationship between the values of n, the square root of n, and the natural logarithm of n for a given range of numbers. This can help in understanding the growth rate and patterns of these functions.

## 2. How is the table for n, sqrt n and ln n created?

The table is created by systematically plugging in values of n from 0 to nmax into the respective equations for square root and natural logarithm. The resulting values are then organized into a table for easy comparison.

## 3. What is the significance of including values for 0 in the table?

Including values for 0 allows for a complete understanding of the functions, as it is often a special case in mathematics. Additionally, it helps to visualize the behavior of the functions as the input approaches 0.

## 4. Can this table be used for any value of nmax?

Yes, the table can be used for any value of nmax. However, as the value of nmax increases, the table may become more difficult to read and interpret due to the increasing number of rows and columns.

## 5. How can this table be useful in scientific research?

This table can be useful in scientific research as it can provide insights into the behavior and growth rate of functions involving n, sqrt n, and ln n. It can also be used for data analysis and comparison of different datasets. Additionally, it can serve as a reference for future experiments and calculations involving these functions.

• Programming and Computer Science
Replies
5
Views
4K
• Programming and Computer Science
Replies
12
Views
1K
• Programming and Computer Science
Replies
66
Views
4K
• Programming and Computer Science
Replies
12
Views
1K
• Programming and Computer Science
Replies
4
Views
773
• Programming and Computer Science
Replies
10
Views
942
• Programming and Computer Science
Replies
35
Views
2K
• Programming and Computer Science
Replies
4
Views
1K
• Programming and Computer Science
Replies
39
Views
3K
• Programming and Computer Science
Replies
5
Views
867