arrays in c

13

Category:

Business


5 download

DESCRIPTION

Arrays in c

TRANSCRIPT

Page 1: Arrays in c
Page 2: Arrays in c

Arrays in c programming

muhammed [email protected]/in/

profilename8547712876

Typing Speed:

Page 3: Arrays in c

Arrays in c programming

• An array is a collection of same type of elements which are sheltered under a common name.

Page 4: Arrays in c

Different types of arrays

•1- dimensional array

•2-dimensional array

•Multi-dimensional array

Page 5: Arrays in c

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};

Page 6: Arrays in c

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;• }

Page 7: Arrays in c

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];

Page 8: Arrays in c

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;• }

Page 9: Arrays in c

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];

Page 10: Arrays in c

• 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.

Page 11: Arrays in c

• 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]);• }• }• }

• }

Page 12: Arrays in c

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

Page 13: Arrays in c

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]