introducing arrays in c. purpose: storing multiple data items under the same name example: salaries...
TRANSCRIPT
Introducing Arrays Introducing Arrays in Cin C
PURPOSE:PURPOSE:
Storing multiple data items under the same nameExample: Salaries of 10 employeesPercentage of marks of my dear 63 students
Note: The data items in an array must be of the same data type (int,float,char)
Array -definitionArray -definition
Array is a sequenced collection of related data items that share a common name
Declaring an array Declaring an array variablevariable
int marks[63]int salary[10]float temperature[100]
Note: static keyword can be used to intialise the values to 0
ie static float temperature [ ]
Representation of Arrays in Representation of Arrays in memmorymemmory
salary[10]
Accessing Elements of an Accessing Elements of an arrayarray
We make use of the index value to access the elements of an array
ie salary[0]-Represents 1st element of an arraysalary[1]-Represents 2nd element of an arraysalary[6]-
salary[9]-
Array initialisationArray initialisation
int marks[5]={30,23,44,45,32}float temp[ ]={22.5, 54.6, 71.5, 8.7}
Entering data into an Entering data into an arrayarray
for(i=0;i<63;i++){
printf(“Enter marks”);scanf(“%d”,&marks[i]);
}
Reading data from an Reading data from an ArrayArray
for(i=0;i<63;i++){printf(“%d”,marks[i]);}
PROBLEM 1: PROBLEM 1: Write a program to enter the Write a program to enter the marks obtained by 5 marks obtained by 5 students in a test into an students in a test into an array and then display itarray and then display it
PROBLEM 2: PROBLEM 2: Write a program to enter the Write a program to enter the marks obtained by 63 marks obtained by 63 students in a test into an students in a test into an array and then find the array and then find the highest mark in the listhighest mark in the list
PROBLEM 3: PROBLEM 3: Write a program to find Write a program to find the average marks the average marks obtained by class of 63 obtained by class of 63 students in a teststudents in a test