Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Mathematics ProgramRSS Feeds

Program to read 2D array and display it row by row and its sum

Posted By: Easy Tutor     Category: C++ Programming     Views: 10942

A C++ Program to declare an 2D array of 3*4 size of type int and initialize it by 5,10,15,... and print the contents of the array in a single line ,row by row and also display its sum.

Code for Program to read 2D array and display it row by row and its sum in C++ Programming

 #include<iostream.h>
 #include<conio.h>

 void print_array_single_line(int [3][4]);
 void print_array_row_by_row(int [3][4]);
 int sum_array(int [3][4]);

 main()
    {
       clrscr();

       int array[3][4]={ {5,10,15,20},{25,30,35,40},{45,50,55,60} };

       cout<<"\n The contents of the array along a singal line :"<<endl;
       print_array_single_line(array);


       cout<<"\n\n\n The contents of the array row by row :"<<endl;
       print_array_row_by_row(array);

       cout<<"\n\n\n Sum of the array is = "<<sum_array(array)<<endl;

       getch();
       return 0;
    }

 /*************************************************************************///------------------  print_array_single_line(int [3][4])  --------------///*************************************************************************/void print_array_single_line(int array[3][4])
    {
       for(int count_1=0;count_1<3;count_1++)
      {
         for(int count_2=0;count_2<4;count_2++)
        cout<<" "<<array[count_1][count_2];
      }
    }

 /*************************************************************************///-----------------  print_array_row_by_row(int [3][4])  ----------------///*************************************************************************/void print_array_row_by_row(int array[3][4])
    {
       for(int count_1=0;count_1<3;count_1++)
      {
         for(int count_2=0;count_2<4;count_2++)
        cout<<" "<<array[count_1][count_2];

         cout<<endl;
      }
    }

 /*************************************************************************///-------------------------  sum_array(int [3][4])  ---------------------///*************************************************************************/int sum_array(int array[3][4])
    {
       int sum=0;

       for(int count_1=0;count_1<3;count_1++)
      {
         for(int count_2=0;count_2<4;count_2++)
        sum+=array[count_1][count_2];
      }
       return sum;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to read 2D array and display it row by row and its sum is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 

Other Interesting Articles in C++ Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!