Hey guys, what is up. In this particular post, we will be talking about what is an array in c programming. Types of the array in coding and we will some questions related to the last post that was on nesting of loop questions.

What is array in c programming?

Array in c++ language is a collection of elements. All the elements which are saved in an array are of the similar data type. These are stored together in a contiguous memory location. It has a fixed size. It is referred to by a common name. Array elements always start from zero location. An array is defined using any of the pre-defined data types. It can be defined using char, int, float, etc. In the character array, every element has a size of one byte. In an integer array, every element has a size of two bytes. 

Types of an array in c programming:

Array in coding are of two types:

  1. One-dimensional array or 1-D
  2. Multi-dimensional array or 2-D

A one-dimensional array or 1-D array is also known as a linear list.

A two-dimensional array is known as a matrix in the singular form. In plural form, it is known as matrices.

Now let us see some questions on the nesting of loops that were related to the previous post.

NESTING OF LOOPS PATTERN MAKING QUESTIONS:

Question 1: Write a program to display a hollow rectangle using stars.

array in programming

Program:

#include <iostream.h>

int main()

{

int row, col;

cout<<“Enter the number of rows in the rectangle: “;

cin>>row;

cout<<“Enter the number of columns in the rectangle: “;

cin>>col;

for(int i=1;i<=row;i++)

{

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

               {

                         if(i==1 || i==row || j==1 || j==col)

                        {

                                    cout<<“*”;

                        }

                        else

                        {

                                    cout<<” “;

                        }

               }

               cout<<endl;

}

return 0;

}

Question 2: Write a program to print the pattern using stars.

array in programming 2

Program:

#include <iostream.h>

int main()

{

               int n;

               cout<<“Enter the value of n: “;

               cin>>n;

               for(int i=1;i<=n;i++)

               {

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

                        {

                                    if(j<=n-i)

                                    {

                                                cout<<” “;

                                    }

                                    else

                                    {

                                                cout<<“*”;

                                    }

                        }

                        cout<<endl;

               }

               return 0;

}

Question 3:Write a program to display the following pattern using numbers

loops quesions 3

Program:

#include <iostream.h>

int main()

{

int n;

cout<<“Enter the value of N: “;

cin>>n;

for(int i=n;i>=1;–i)

{

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

               {

                        cout<<j<<” “;

               }

               cout<<endl;

}

return 0;

}

Question 4: Write a program to display the pattern using nesting of loops

loops quesions 4

Program:

#include <iostream.h>

int main()

{  

int n;

cout<<“Enter the value of N: “;

cin>>n;

for(int i=1;i<=n;i++)

{

               for(int j=1;j<=n-i;++j)

               {

                        cout<<i<<” “;

               }

               cout<<endl;

}

return 0;

}  

Question 5: Write a program to display the following pattern using the nesting of loops.

array in programming language

Program:

#include <iostream.h>

int main()

{

int i,j,r;

cout<<“Enter the value of R: “;

cin>>r;

for(i=1;i<=r;i++)

{

               for(j=1;j<=i;j++)

               {

                        If ((i+j)%2==0)

                        {

                                    cout<<“1”;

                        }

                        else

                        {

                                    cout<<“0”;

                        }

               }

               cout<<endl;

}

return 0;

}

In the upcoming post, you will be getting information related to the latest technology trend. If you haven’t read about what are programming languages in c++ then go and read this. You can read previous posts by scrolling downwards. Also, stay tuned for the upcoming post.


1 Comment

Aayush Singh · May 9, 2021 at 10:56 am

Op bhai Op

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *