Download presentation
Presentation is loading. Please wait.
1
C++ Arrays
2
Arrays Used to store a collection of elements (variables) type array-name[size]; Meaning: This declares a variable called <array-name> which contains <size> elements of type <type> The elements of an array can be accessed as: array-name[0],…array-name[size-1] Example: int a[100]; //a is a list of 100 integers, a[0], a[1], …a[99] double b[50]; char c[10];
3
Array example //Read 100 numbers from the user
#include <iostream.h> void main() { int i, a[100], n; i=0; n=100; while (i<n) { cout << “Input element “ << i << “: ”; cin >> a[i]; i = i+1; } //do somehing with it ..
4
Problems Write a C++ program to read a sequence of (non-negative) integers from the user ending with a negative integer and write out the average of the numbers the smallest number the largest number the range of the numbers (largest - smallest) Example: The user enters: 3, 1, 55, 89, 23, 45, -1 Your program should compute the average of {3, 1, 55, 89, 23, 45} etc
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.