Lecture 6
Lecture 6
LECTURE #6
ARRAYS
An array is a sequence of same data type. The objects in
an array are also called elements of array.
A= P A K I S T A N
Types of an array
One –dimensional Array
Multi-dimensional Array
ONE DIMENSIONAL ARRAY
One dimensional array or also called linear array.
In nested loop the upper loop is used to change the index value of
the rows and the inner value is used to change the index value of
the columns.
PROGRAM TO PRINT OUT DATA
FROM THE ELEMENTS OF A TABLE
#include<iostream. h> r=r+1;
#include<conio. h> }
Void main () Cout<<“printing data from the
{ table”<<endl;
int abc[2][3], r, c; r =0;
Clrscr (); While(r<=1)
Cout<<“input data into table”<<endl; {
r=0; C=0;
While(r<=1) While(c<=2)
{ {
C=0; Cout<<abc[][]<<“\t”;
While(c<=2) C=c+1;
{ }
Cout<<“enter value in row =” ; Cout<<endl;
Cout<<r<<“column =”<<c<< “ ”; r=r+1;
Cin>>abc [r] [c]; }
c=c+1; getch();
} }
WRITE A PROGRAM TO INPUT FLOAT DATA TYPE INTO A
TABLE HAVING 5 ROWS AND 4 COLUMNS. FIND OUT THE
MAXIMUM NUMBER ENTERED IN THE TABLE AND PRINT
OUT ON THE SCREEN
#include<iostream. h>
#include<conio. h>
Void main ()
{
int xyz[3][4]={{2,3,10,1},{6,12,16,3},{4,3,13,17}};
int r, c;
For (r=0; r<=2;r++)
{
For(c=0;c<=3; c++)
{
Cout<<xyz[r][c]<<“\t”;
}
Cout<<endl;
}
getch();
}
INITIALIZING CHARACTER TYPE TABLES
The values in a table of “char” type is also assigned in
the same way as other data type.
3. Write a program to sum the diagonal elements of the following 3*3 matrix ?.
A= 1 2 3
4 5 6
7 8 9
B= 1 2 3
4 5 6
7 8 9