arrays in c
Upload: baabtracom-mentoring-partner-first-programming-school-in-india
Post on 07-Nov-2014
417 views
DESCRIPTION
Arrays in cTRANSCRIPT
Arrays in c programming
• An array is a collection of same type of elements which are sheltered under a common name.
Different types of arrays
•1- dimensional array
•2-dimensional array
•Multi-dimensional array
One-dimensional arrays
• One dimensional array have only one subscript under a common name.
• syntax• Data_type array_name[array_size];• Example• int age[5]={2,4,34,3,4};
Example program• #include<stdio.h>• int main()• { • int a[4];• int i;• for ( i = 0; i < 4; i++ ) • {• Scanf(“%d”,&a[i]);• }• for ( i = 0; i < 4; i++ )• printf("a[%d] = %d\n", i , a[i]);• return 0;• }
Two-dimensional arrays
• Two-dimensional array are those type of array, which has finite number of rows and finite number of columns.
• Data_type Array_name [row size][column size];
Example program• #include<stdio.h>• int main()• { • int a[4][4], i , j;• for (i = 0; i < 4; i++)• {• for ( j = 0; j < 4; j++)• {• a[i][j] = 0;• scanf("a[%d][%d] ", i, j, a[i][j]);• }• } • for (i = 0; i < 4; i++)• {• for ( j = 0; j < 4; j++)• {• a[i][j] = 0;• printf("a[%d][%d] = %d \n", i, j, a[i][j]);• }• } return 0;• }
Multi-dimensional arrays
• An array have multiple subscript under a common name.
• Syntax• type name[size1][size2]...[sizeN];• Example• float a[2][6][7][4]….[n];
• Subscripted Variable Rules• Subscripted variables can be double, integer,
or character.• The maximum number of subscripts is dictated by the
compiler vendor. Twelve is common.• Arithmetic expressions may be used for subscripts.• Subscripts must be integer valued.• A statement must be included in your program which
sets aside storage space (dimensions) for your arrays.
• Example programm• #include<stdio.h>• int main()• {• int a[4][4][4], i , j,k;• for (i = 0; i < 4; i++)• {• for ( j = 0; j < 4; j++)• {• for ( k = 0; k < 4; k++)• {• a[i][j][k] = 0;• scanf("a[%d][%d][%d] ", i, j,k, a[i][j][k]);• }• }• }• for (i = 0; i < 4; i++)• {• for ( j = 0; j < 4; j++)• {• for ( k = 0; k < 4; k++)• {• a[i][j][k] = 0;• printf("a[%d][%d][%d] = %d \n", i, j,k, a[i][j][k]);• }• }• }
• }
If this presentation helped you, please visit our page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Start up VillageEranakulam,Kerala, India.
Email: [email protected]