0% found this document useful (0 votes)
55 views8 pages

Computer Programming For Engineering: (Course Code: EECP 1290)

This document discusses arrays in computer programming. It defines an array as a sequence of variable names that share the same name. Arrays are useful for storing large amounts of data of the same type, such as in applications involving student databases, banking, industry, and ticket reservations. The document provides examples of array declarations and programs to print the elements of an array in forward and reverse order using for loops.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views8 pages

Computer Programming For Engineering: (Course Code: EECP 1290)

This document discusses arrays in computer programming. It defines an array as a sequence of variable names that share the same name. Arrays are useful for storing large amounts of data of the same type, such as in applications involving student databases, banking, industry, and ticket reservations. The document provides examples of array declarations and programs to print the elements of an array in forward and reverse order using for loops.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Computer Programming for Engineering ( Course Code: EECP 1290 )

Arrays Concept with Animations


Lecturer : P. GOPI KRISHNA B.Tech, M.Tech, (Ph.D), MIE,MISTE

Today Topics

1. What is Array? 2. Why Use Array?


3. Where Arrays will be useful? (i.e Applications of Arrays)

4. How arrays are used with some


Programming Examples

1. Introduction to Arrays:
char v[0]=a, v[1]=e ,v[2]=i ,v[3]=o ,v[4]=u ; The same will be represented easily as char v[5]={ a , e , i , o, u} ; char grade[6]={ A, B , , D , E , F} char fruits[4]= {apple, banana, cherry, mango } char subject[4]= { C++, Physics,Chemistry, Maths} int marks[11]={100, 90, 80 , 70, 60, 50,40,30,20,10,0} int speed[5]={80, 60, 40,20,0} In the above lines vowel[5], grade[6], fruits[4], subject[4], marks[11], speed[5] are ARRAYS.

What is Array ?
Here c[0], c[1] ,c[2] . . . ., c[10], c[11] are Variable names. Now let us define array ? An array is a sequence of variable names that shares same name c for variables c[0], c[1] ,c[2] . . . ., c[10], c[11] . A single dimensional array is just like one row of MATRIX. A multi dimensional array is just like MATRIX with rows and columns.

Name of array is c
c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] -45 6 0 72 1543 -89 0 62 -3 1 6453 78

int c[12]={-45,6,0,72,1543,-89,0,62,-3,1,6453,78}

Position number of the element within array c

Why use Array ?

Arrays are useful to store a large number of values of the same data type. Where Array are useful? (Applications) To create students data base with marks, details Bank Applications, Industry &Scientific applications , Air Ticket Reservations, . In all these applications a large data will be stored

and retrieved (recall).

How Arrays Used ?


The array syntax is as follows Datatype ArrayName[Length]; Examples: char grade[6]={ A, B , , D , E , F} char fruits[4]= {apple, banana, cherry, mango } char subject[4]= { C++, Physics,Chemistry, Maths} int marks[11]={100, 90, 80 , 70, 60, 50,40,30,20,10,0} int speed[5]={80, 60, 40,20,0}

Program to Print Elements of Array


int _tmain(int argc, _TCHAR* argv[])

{int i; M[0] M[1] M[2] M[3] M[4] int Marks[5] = {96, 85, 59, 90, 76}; for(i=0 ; i <= 4 ; i=i+1 ) { cout<<Marks[i]<<" ";Marks[4]=90 Marks[0]=96 96 85 59 90 76 Marks[1]=85 Marks[2]=59 Marks[3]=90 } getch(); return 0; } Program Ends
1 4 0 <=4 2 3 5 <= 4YES YES i= 4+1=5 NO 0+1=1 1+1=2 2+1=3 3+1=4

Program to Print Elements of Array in REVERSE ORDER int _tmain(int argc, _TCHAR* argv[])

{int i; M[0] M[1] M[2] M[3] M[4] int Marks[5] = {96, 85, 59, 90, 76}; for(i=4 ; i >= 0 ; i=i-1 ) { cout<<Marks[i]<<" ";Marks[0]=96 Marks[4]=76 76 90 59 85 96 Marks[3]=90 Marks[2]=59 Marks[1]=85 } getch(); return 0; } Program Ends
-1 NO 4 >=0 3 2 1 0 >= 0YES YES i= 0-1=-1 4-1=3 3-1=2 2-1=1 1-1=0

You might also like