👉👉👉 Computer Science 12th Class Notes (Main Page)
Unit 5: Arrays and String
5.2.3. Accessing and Filling a 2D array
2D arrays are generally accessed row by row using a nested loop. The row index is used as the outer loop variable and the column index as the inner loop variable.For example to fill an array using the cin function:
int demo[3][2];
for( i=0;i<3;i++ )
{
for( j=0;j<2;j++ )
{
cin>>demo[ i ][ j];
}
}
for( i=0;i<3;i++ )
{
for( j=0;j<2;j++ )
{
cin>>demo[ i ][ j];
}
}
Example 1:
• Write a program that reads integer values in an array of 3 rows and 4 columns and finds the sum of all the values.#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int k[3][4], sum=0;
for(int i=0; i<=2; i++)
{
for(int j=0; j<=3; j++)
{
out<<“Enter a number: “;
cin>>k[i][j];
}
}
for(int a=0; a<=2; a++)
{
for(int b=0; b<=3; b++)
sum = sum + k[a][b];
}
cout<<“Sum of all values is: “<<sum<<endl;
getch();
}
#include <conio.h>
void main()
{
clrscr();
int k[3][4], sum=0;
for(int i=0; i<=2; i++)
{
for(int j=0; j<=3; j++)
{
out<<“Enter a number: “;
cin>>k[i][j];
}
}
for(int a=0; a<=2; a++)
{
for(int b=0; b<=3; b++)
sum = sum + k[a][b];
}
cout<<“Sum of all values is: “<<sum<<endl;
getch();
}
12th Class (HSSC-II) Computer SLO Based Key Point Notes
(National Book Foundation - As Federal Textbook Board, Islamabad Based on National Curriculum Pakistan 2023-2024 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
(National Book Foundation - As Federal Textbook Board, Islamabad
Based on National Curriculum Pakistan 2023-2024 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
{Contact WhatsApp # 03339719149 for Class-XII Computer Science Complete SLO-Based Key Points notes in pdf format as well as in PowerPoint Presentation for preparing/delivering the Lectures}👇👇👇👇👇👇👇👇👇👇
************************************👉👉👉 Computer Science 12th Class Notes (Main Page)
************************************
(National Book Foundation - As Federal Textbook Board, Islamabad Based on National Curriculum Pakistan 2026-2027 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
(National Book Foundation - As Federal Textbook Board, Islamabad
Based on National Curriculum Pakistan 2026-2027 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
{Contact WhatsApp # +923339719149 for Class-XII Computer Science Complete SLO-Based Key Points notes in pdf format as well as in PowerPoint Presentation for preparing/delivering the Lectures}
Note: Write me in the comments box below for any query and also Share this information with your class-fellows and friends.
0 Comments
Note: Write me in the comments box below for any queries and also Share this information with your class-fellows and friends.