Array
In C++ the array, which stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type
All arrays consist of contiguous memory locations. The lowest address
corresponds to the first element and the highest address to the last
element.
An array is a collection of data that holds fixed number of values of same type. For example:
int age[100];
Now we took an example of Array in C++
#include<iostream.h>
#include<conio.h>
void main()
{
int n[5], sum = 0;
cout << "Enter 5 numbers: ";
for (int i = 0; i < 5; ++i)
{
cin >> n[i];
sum = sum + n[i];
}
cout << "Sum is = " << sum << endl;
getch();
}
OUTPUT
Enter 5 numbers: 3
4
6
4
2
Sum is = 19
0 comments:
Post a Comment