Posts

Showing posts from February, 2021

Finding (positive - negative - odd - even - zero) numbers in an array

Image
Welcome again to a new lesson and a new example. We're continuing practicing what we learned in the conceptual lesson about arrays ( Taking inputs from the user, storing them in a (1D-2D-3D) array and printing them on the screen in c++ ). In today's example, we make a simple program in C++ that searches a one-dimensional array for some specific numbers and returns the count of numbers that matches the specified type. The question says: Take 20 integer inputs from the user and output the count of the following:  1. Positive numbers. 2. Negative numbers. 3. Odd numbers. 4. Even numbers. 5. Zeros. Step 1: Declare a 20-element one-dimensional array.      int array[20]; Step 2: Prompt the user to enter 20 integer values and store them in the previously declared array - use a ( for ) loop to pass through the array indexes.      std::cout << "Enter twenty integers:\n";      for (int i = 0; i < 20; i++)      { ...

Searching an array for an entered value

Image
Hi everyone, welcome to a new lesson and new example. Today we have an example on arrays, specifically, single dimensional arrays. We deep dived previously in executing input/output on arrays but conceptually. In this article and the coming ones, we're going to practice the concepts we learned. If you want an explanatory article about arrays from the scratch, I would rather reading the following blog before reading this. Otherwise, if you have enough knowledge about arrays and doing I/O on them, and you want something more hands on, just complete reading this article. Taking inputs from the user, storing them in a (1D-2D-3D) array and printing them on the screen in c++ Now let's start solving our example. The question says: Take 10 integer inputs from the user and store them in an array. Again ask the user to enter an integer, then the program should tell the user whether the entered integer exists or not. Step 1: Create a single dimensional array with a size of 10. int array[1...

Taking inputs from the user, storing them in a (1D-2D-3D) array and printing them on the screen in c++

Image
Hey there. In this lesson we're going to explain (1D - 2D - 3D) arrays in some depth. First, we're going to take a snapshot on single dimensional arrays, inputting and outputting values to/from them. Next, we're going to move on to 2D and 3D arrays , do the same operations on them and finally take examples on each type. First of all, what in the world is an array? let's take an idea about it. What is an array in programming? Away of mathematical concepts, let's assume that we're asked to store a student age. Really easy, right? Just make an integer variable, name it "age", assign the student age value to it, and the world is happy. int age = value; But what if we get to store more than one "age" value like 10 records. Creating 10 integers right? and what if they are 100. Creating a hundred integer variable, one after another, would be kind of boring and wasting time. So what is the solution.. Here are arrays came ...