Data_type Name_Of arraylrow_sizel{column_sizel
100 is getting created. The Desk
f an two dimensional ang
For example
int a[10][10);
By this allocation the memory block of 10 x 10 so
loops can be effectively used to access all the elements
will take a sample example to explain this idea.
for(i=0;i< =2;i++)
{
for(j=0;j<=2;j+ +)
{
TECHNICAL PUBLICA Tions® - an up-thrust for knowledgeCTrogentnminng wed Tatn Senet recy Programming Fandarontata
scant" %a Rah:
}
)
Execution of Nested for Loop
Initially the value of i-O at that time
j-0 it will store the element in af0]{0]
j=1 it will store the element in af0][1]
j-2 it will store the element in af0]{2]
Next time i will be incremented by 1 and now
Again
}-0 it will store the element in a{1}[0]
j-1 it will store the element in a{1][1]
j-2 it will store the element in a{1][2]
Next time i will be incremented by 1 and now i
j-0 it will store the element in af2][0]
jo1 it will store the element in af2][1]
j-2 it will store the element in af2][2] \
Since now value of i and j has reached to 2 the scanning procedure will get terminated as
condition is i<=2 and j<=2. Thus all the elements from a[0][0] to a[2][2] get scanned
Array positions
00 a01 02
a10 att at2
20 a21 a22
Fig. 1.10.4 a[0}(0} to af2)(2)
Ex. 1.10.1 How two dimensional arrays are created in C? Write a C program to generate
4 population survey having citizen's record stored as a collection of yeur-wise
population, CURIS EST
Sol. Iwo dimensional array - Refer section 1.103
include
int main ()
—_
TECHNICAL PUBLICATIONS® « aa up-thiust for kriowlodgeCProgramming and Data Structures
{i
int ar[3}[3), ij;
for (i= 0i<3;i4+ +)
{
140 C Programing Fag
wan
print{("\nEnter the population for country#%d",(i+1));
for j=0j<3j++)
{
printf("\n Enter the population for Year#%d",(j+1));
scanf("%d" Sari] ij);
}
printf("\n printing the population ....\n");
printf("\n\t country#1 country#2 country#3\n")
print{("\n-- An");
for(i=0i<3;i++)
{
printf("Year#%d |",(i+1));
~for (j=0;j<3;j++)
{
printf("\t%dL'arr[il fj);
+
printf("\n");
+
return 0;
Simple Programs
> Program 1.11.1 : Sorting Program
[OCHS OOOO ONIONS IIIA OO
Program for sorting the elements
Hon UN Un OnE Hn USunHnionnreaieinrsts/
/* Header Files*/
#include
#include
#include
/*Declaration*/
TECHNICAL PUBLICATIONS® - an up-thrust for knowledgeProgramming and Data Structures tay C Programming, Fundamentals
void sort(int a[20],int n)
‘ int ij.m,temp;
forli=0;iali+1])
{ temp=alj];
aljl=alj+1;
alj+1)=temp;
/(Printing the sorted array//
O;i Program 4.11.2 : Searching Program
[Sta eats eeeennnnaae nnn ennn etna RAR ARR E RARER RR RREREAE EIST TEE ES ES
Program to perform the linear search operation
#include
#include
#define MAX 10
int a[MAX],n,i;
I,
The create Function
Input :none
Output:none
Called By: main
Calls:none
/
void create()
if
printf("\a How Many Elements");
scanf("%d",&n);
printf("\n Enter The Elements");
for(i=0;i
#include
#define MAX 5
void main()
{
int a[MAX][MAX],b[MAX][MAX],c[MAX][MAX];
int m1,n1,m2,n2;
int choice;
int i
char ans="y’;
void Print_Matrix(int o[MAX|{MAX|,int ,int );
void Addition(int a[MAX]{MAX|,int m1 int n1,int b[MAX][MAX|,int c[MAXI[MAX]);
void Subtraction(int al MAX]{MAXi,int m1,int n1,int b{MAXI[MAX],int c[MAX|[MAX));
void Transpose(int a[MAX}[MAX|,int m1,int n1,int c[MAX}[MAX]);
void Multiplication(int a[MAX}[MAX} int ,int ,int bIMAX]{MAX(,int ,int ,int c[MAX][MAX]);
printf("\n\t Program for performing matrix operations "
printf("\n Enter data for matrix a \n");
printf("\n Enter the total number of rows ");
scanf(“%d",&m1);
printf("\n Enter the total number of columns ");
scanf("%d",&n1);
printf("\n Enter the elements\n");
for(i=0;i
int main()
{
int A(3I(3),B(3)(3},C[3}31,TempI3}13}.ij.m.n;
printf("Enter the order of the matrix::\n");
scanf("%d%d",8m,&n);
printf("Enter the A matrix::\n");
for(i
{
for(j=0,j