Single Demensional Array (SDA) : TH TH TH TH
Single Demensional Array (SDA) : TH TH TH TH
Single Demensional Array (SDA) : TH TH TH TH
2019
ARRAY
1:- Array is not a primitive data type, because array is an abstract data type(ADT) .
2:- Array is a collection of or group of similar data type .
3:- Array always provide consecutive memory.
4:- array always started by 0th element.
5:- The name of array refer to the base address(starting address of allocated
Memory.
6:- Array always referred to the static memory means we can not change the
Size of memory or deallocated memory during execution.
7:- Array doesn’t not support to the bound checking.
Type Of Array
1. Single Demensional Array ( SDA )
2. Double Demensional Array ( DDA )
3. Multi Demensional Array ( MDA )
int x[10];
Address 100 102 104 106 108 110 112 114 116 118
X 2 5 6 10 1 12 5 11 3 16
Position 0 1 2
3 4 5 6 7 8 9
#WAP to enter all elements in an array and print it and printf in reverse also.
#include<stdio.h>
void main( )
{ int x[10 ] , i;
printf("\nEnter Array X ");
#WAP to find the biggest no and its position from array of 10 elements
#include<stdio.h>
void main( )
{ int x[10 ] , i , big = -32768 , pos ;
printf("\nEnter Array X ");
for(i=0 ; i<10 ; i++)
{ scanf("%d", &x[ i ] );
if ( x[ i ] > big )
{ big = x[ i ] ;
pos = i + 1 ;
}
}
printf("\nBiggest no = %d and position = %d " , big , pos );
}
#WAP to find the smallest no and its position from array of 10 elements
#include<stdio.h>
void main( )
{ int x[10 ], i ,small = 32767 , pos ;
printf("\nEnter Array X ");
for(i=0 ; i<10 ; i++)
{ scanf("%d", &x[ i ] );
if ( x[ i ] < small )
{ small = x[ i ] ;
pos = i + 1 ;
}
}
printf("\nSmallest no = %d and position = %d " , small , pos );
}
}
#WAP to sort the all elements in an arrar( using bubble sort)
#include<stdio.h>
void main()
{ int x[10],i,j,t;
printf("\nEnter 10 number:");
for(i=0;i<10;i++)
scanf("%d" , &x[ i ] );
for( i=0 ; i<10 ; i++ )
{ for( j=0 ; j < 9 - i ; j++ )
{ if(x[ j ] > x[ j+1] )
{ t =x[ j ] ;
x[ j ] =x [ j+1 ] ;
x[ j+1 ] = t ;
}
}//end of j loop
}//end of i loop
printf("\n after sorting");
for( i=0; i<10; i++)
printf(" %d" , x[ i ]);
Two dimension array is called DDA. Or collection of single dimension array is called
DDA
int X [ 3 ] [ 4 ] ;
2 3 7 4
1 8 9 3
6 2 4 5
Actual format
2 3 7 4 1 8 9 3 6 2 4 5
0 1 2 3 4 5 6 7 8 9 10 11
INITALIZATION OF DDA
int x[ 3 ] [ 4 ] ;
int x[ 3 ] [ 4 ] = {2,3,7,4,1,8,9,3,6,2,4,5};
int x[ 3 ] [ 4 ] ={ {2,3,4,5},{1,8,9,3},{6,2,4,5} };
int x[ 3 ] [ 4 ] ={2,3,7,4,1,8,3,6};
int x[ 3 ] [ 4 ] ={ {2,3,4},{1,2},{6,9} }
int x[ 4 ] [ ] = { 5,7,1,2,8,9 };
int x[ ][ 3 ] = { 5,7,1,2,8,9 };
#WAP to scan the all elements into 3*4 matrix and print them.
#include<stdio.h>
void main()
{ int x[3][4],i,j;
printf("\nEnter Matrix X ");
for(i=0;i<3;i++)
{ for( j=0 ; j<4 ; j++ )
scanf("%d" , & x [ i ] [ j ] );
}
printf("\nEntered Matrix Is :\n");
for(i=0;i<3;i++)
{ for( j=0 ; j<4 ; j++ )
printf(" %d" , x [ i ] [ j ] );
printf("\n");
}
}
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf(" %d" , x[ i ][ j ] );
}
printf(" %d \n ", sumr [ i ] );
FACULTY : SANDEEP SAHU( M.Tech(CSE))Page 7
AIM POINT INFOSYSTEM PVT. LTD. 2019
printf("\n");
}
}
}
}
for( i=0 ; i<3 ; i++)
{ for( j=0 ; j<4 ; j++ )
printf(" %d", x[ i ] [ j ] );
for( j=0 ; j<4 ; j++ )
printf(" %d", y[ i ] [ j ] );
}
}