about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

Multidimensional Array Program in C Plus Plus to Find Table


Multidimensional array program in C++


Multidimensional array is the most interesting array. If you have understand the concept of multidimensional array then using this concept you can implement the same logic in one or two statements which when using the array may consume up to more than 20 statements.

 


In C++ multidimensional arrays concept is widely used and today we will cover how to print the table of a number using the multidimensional array in C++ . We have already explore 4 different types to print the table of any number in C++ on screen. But this will be more interesting and tricky way. So let’s start.



                            C++ Program of  Multidimensional Array to Print Table


Code

//softoset.blogspot.com

#include<iostream>

using namespace std;

int main()

{

            int num;

            cout<<"Enter Number to Find Table"<<endl;

            cin>>num;

    int table[1][20];

            for(;int i=num;)

            {

                        for(int j=1;j<21;j++)

                        {

                                    int ans=i*j;

                                    cout<<i<<" * "<<j<<" = "<<ans<<endl;

                        }

                        break;

            }

            return 0;

}

 

Output

This is the sample run of this program.

 

 

 

program in C plus plus of Multidimensional array

 

 

You can see that when user entered the number 9. This program display the table of nine up to 20.

 

 

Algorithm

Ø Get a number form user to display table in variable num.

Ø  Declare a two dimensional array of [1][20], if you want to print the table of one number up to 20.

Ø  Use a for loop which only initialize the variable i = num in for loop.

Ø  In the body of this for loop use another for loop which have initialized a variable j and keeps incrementing it until it is less than 21.

Ø  In the body of this for loop multiply the num with number form 1 to 20 and display them of the screen.

Ø  When value of j will be 21 inner for loop will terminate and outer for loop will automatically be terminated because we have use the break statement.

Ø  Finally control will return to the system by return 0; statement.

 

 

 

That’s it! Thank to you for your kind attentions. Have any trouble in understanding this code comment us to be clear the concepts.


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents