Write a program to print table of any number in c++

Could the number of variables used deceased further?

Write a program to print table of any number in c++

The exercise is: Assume that you want to generate a table of multiples of any given number. There must be some way to tell the computer to print a newline after every maxcol number of executions -- this is acheived by the if statement. Hen the statement Get line extracts characters from the stream as unformatted input and stores in 'stringArray' name character array. Write a program that allows the user to enter the number and then generates the table, formatting it into 10 columns and 20 lines. In the previous version every statement does some important function every single time it is executed. Next is int main. Use two loops or one loop plus an if statement? The most obvious solution was to keep track of current position in the table. Using a single for loop with an if statement inside: Another idea was to force myself to use only one loop because, in principle, the second loop should be redundant as we need to increment only pos to find the value at that position. In the second version I removed one loop and instead used an if statement? Here are few other related articles for you to read:.

Now, for removing naming conflict you can use namespace statement within a program. Strings written within the double quotes of cout are used to print any message on the screen.

Now, you have to declare a character array char stringArray[]; Like this and name that array, here 'stringArray' and requests for a memory location of bytes fixed storage.

How to create a table in c++

I am solving the first exercise questions of chapter-3 loop and decisions. And after every maxcolth position print a newline. Use two loops or one loop plus an if statement? In the second version I removed one loop and instead used an if statement? Which one would be faster at run time? The outer while loop puts a newline and repeats again. As per the exercise the numbers 7, 14, Could the number of variables used deceased further? Keep track of current row and column: The idea was to locate the current position by knowing the current row and column of that position.

And finally the return 0; statement is used to return an integer type value back to main. Here are few other related articles for you to read:.

how to create a table in c++

The most obvious solution was to keep track of current position in the table. There must be some way to tell the computer to print a newline after every maxcol number of executions -- this is acheived by the if statement.

Interaction with the program should look like this only the first three lines are shown : Enter a number: 7 7 14 21 28 35 42 49 56 63 70 77 84 91 98 Using a for loop inside while loop: I've written solution for user-defined number of columns and rows. The beauty of this approach is that the way current position is determined allows us to print the multiplication table in vertically increasing manner too.

Using a single for loop with an if statement inside: Another idea was to force myself to use only one loop because, in principle, the second loop should be redundant as we need to increment only pos to find the value at that position.

Rated 10/10 based on 74 review
Download
C++ Program for Sum of squares of first n natural numbers