/* This program demonstrates * 1. Working with numbers and digits * 2. Introduction to arrays * * Arrays * An array is a collection of variables that satisfies the following properties: * 1. All the variables in the array are of the same type. * 2. All the variables share the same name and are accessed by an index. * 3. The elements (individual variables) are ordered and start at index 0. * 4. The elements are in continuous memory locations. * */ #include #include using namespace std; int main() { int num; cin>>num; /* to count the number of digits in a number: * We keep dividing by 10. Every time we do that, we remove the last digit. * If the number is not 0, then there are more digits, so count 1 digit. * Repeat until the number becomes 0 */ int numDigits = 0; while(num != 0) { numDigits ++; num = num / 10; } cout<<"Number of digits: "<< numDigits<>array[i]; } cout<<"Enter the element at index 4: "; cin>>array[4]; return 0; }