Unit 3 : Array
Arrays - The meaning of an array, One-dimensional and Two-dimensional arrays, Declaration and initialization of arrays, Reading, Writing and Manipulation of arrays, Multidimensional arrays
Strings - Declaring and Initialization character array, Reading and Writing string to/from terminal, Arithmetic operations on characters, Putting strings together, String handling functions, Searching and Sorting of Arrays
Arrays are a fundamental data structure used to store a collection of elements of the same data type under a single variable name.
Arrays store elements of the same data type in contiguous memory locations. This means the elements are stored one after another in memory.
They are declared with a specific size, which determines the number of elements it can hold. This size cannot be changed after the array is declared.
Individual elements are accessed using an index, which starts from 0. The first element has index 0, the second element has index 1, and so on.
Syntax: type arrayName [ arraySize ];
Exercise 5: Write a program to store daily temperatures for a week, and print the average temperature.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float Temp[7],Sum_Temp=0.00, Avg_Temp = 0.00;
cout<<"Enter the temperature for each day : \n";
for(int i = 0;i<=7;i++)
{
cout<<"Day "<<i+1<":";
cin>>Temp[i];
}
for(int i = 0;i<=7;i++)
{
Sum_Temp = Sum_Temp + Temp[i]
}
Avg_Temp = Sum_Temp/7;
cout<<"The average temperature over a week is :" <<Avg_Temp;
getch();
}
Exercise 6: Write a program to carry out MATRIX addition and subtraction.
Exercise 6: Implement a program to demonstrate String handling functions