The basics of programming in c++ for beginners

Tasks: One-dimensional arrays C ++

Getting to the solution of tasks, read articles Arrays in C++  and The random number generator rand(), if you have not read them.   Try to address the proposed tasks independently and watch our decisions only in extremis.

1. Create an array of type int on 10 elements and fill it with random numbers from 7 to 14. After filling overwrite all numbers, who for more than ten:  from the stored value to take away 10.  For example the number is stored in the cell 12: 12 – 10 = 2. Write to this cell 2 Writing the new value, use composite(combined) statements.

2. To fill an array of elements 50 odd numbers from 1 to 99. (use the operation remainder of the division, to check on the number of parity)

3. Declare three arrays. The first two to fill with random values ​​from 10 to 30. In the third elements of the array to record the amount of the corresponding elements of the first two sets. (in the third cell zero – the sum of zero cells first and second arrays, and so on). Then, find the arithmetic mean of the elements of the third array, the maximum value and minimum value, which it holds.

110 thoughts on “Tasks: One-dimensional arrays C ++

  1. HELP PLEASE!)
    Ng(m),Avt(m),God (m)-creating arrays with book titles, author tags and release years. Calculate the earliest publication year of each author's books. How many books start with the letter 'C' no more 30 characters?

  2. PLEASE YOU CAN SOLVE ANY OPTION!!!)
    Option 1. Create array A (20), where Ai = 2 * i + (- 1) i + 3,5. Create array B (20), consisting of elements A (20), whose value is doubled. Calculate the mean D- K and T, where K – number of negative elements of array B, a T – smallest element of array B.

    No. Option 2. Create an array Y (n), each element of which is calculated by the formula yi = 2sinxi + 1,2, x1, xh-input. Calculation of the number of elements of mass Y, whose values ​​are in the range (a, b). Calculate the sum of the elements of indices of odd numbers.

    No. Option 3. Create array D (40). Create array Z from elements of array D with absolute values ​​at most 40. The values ​​in the Z array <Calculate Element Count Zsr.

    No. Option 4. Creating Arrays A (20), B (20). Create array C (20), where Ci = min (Ai, With a). Calculate the number of elements in array C with multiple integer values ​​m.

    # 5 options. Create an R array (20). D = max | Rsr-Ri | calculation of the number. Replacing an array with index elements k and t. Calculate Rmax.

    No. Option 6. Calculate the values ​​of the function y = exi + 0,3, where x [x1, xn] xh = 0,15. Put the function values ​​into an array. Calculate the average of a function and the number of values ​​in a range [a, b].

    No. Option 7. Create an array from 20 elements. Arrange the array in descending order. Calculate the sum of positive elements and the product of elements, whose value is 3.

    No. Option 8. Creating arrays X (20), Y (20). Creating an array D (20) as array X, Y as differences between major and minor elements. DSR calculation. Calculate negative number (k) array D. Adjust array D in descending order.

    No. 9 option. Fam (n), D (n), V (n) – creating arrays, consisting of surnames, positions and ages of the company's employees. Calculation of the number of employees, working in each department of the enterprise. Find the average age of employees and the largest employee for free.

    No. 9 option. Ng (m), Avt (m), God (m) – create arrays of book titles, author tags and publication years. Count the number of books by each author in the year of earliest publication. How many books contain no more than 30 signs, starting with the letter "C"?

  3. Task number 1.
    Trading company "Vostok" at the end of each month sums up the results, that is, it enters the book of expenses and sales proceeds. Will compose a program to calculate the amount of income received for each quarter and determine in which quarter the minimum income was received.

    1. #include
      #include

      using namespace std;

      int main()
      {
      setlocale(LC_ALL, “rus”);
      srand(time(NULL));

      int const SIZE = 3;

      int arr1[SIZE] = {};
      int arr2[SIZE] = {};
      int arr3[SIZE] = {};
      int arr4[SIZE] = {};

      int sum1 = 0;
      int sum2 = 0;
      int sum3 = 0;
      int sum4 = 0;

      for (int i = 0; i < SIZE; i )
      {
      arr1[i] = 1+ rand() % 10;
      sum1 += arr1[i];

      }
      cout <<"Сумма доходов за первый квартал: "<< sum1 << endl;

      for (int i = 0; i < SIZE; i )
      {
      arr2[i] =1+ rand() % 10;
      sum2 += arr2[i];
      }
      cout << "Сумма доходов за второй квартал: " << sum2 << endl;

      for (int i = 0; i < SIZE; i )
      {
      arr3[i] = 1 + rand() % 10;
      sum3 += arr3[i];
      }
      cout << "Сумма доходов за третий квартал: " << sum3 << endl;

      for (int i = 0; i < SIZE; i )
      {
      arr4[i] = 1 + rand() % 10;
      sum4 += arr4[i];
      }
      cout << "Сумма доходов за четвертый квартал: " << sum4 << endl;

      int min = 0;

      if (sum1 < sum2 && sum1 < sum3 && sum1 < sum4)
      min = sum1;
      else if (sum2 < sum3)
      min = sum2;
      else if (sum3 < sum4)
      min = sum3;
      else
      min = sum4;

      cout << "Минимальный доход квартала: " << min << endl;
      return 0;

      The code may not be so pretty, but it works.

  4. 1. Given an array of numbers. Define, how many pairs of identical neighboring elements are in it.
    2. Given an array of numbers. Find the sum of multiples 3, and count their number.
    3. Find the product of array elements with fuzzy indices, dimension 20, int data type;
    4. Given an array of numbers, data type int, dimension 24, replace all numbers 6 on 0, count the number of substitutions.
    5. Given an array of numbers with dimension 20, type int, form an array from it, which will be filled only with those values ​​of the first array, with even indices.
    6. Given an array of numbers with dimension 20, int data type, form another array from this array, whose size is two times smaller.
    7. Given an array of numbers, data type float, dimension 12. Count how many times a number occurs 3,1.

  5. Write a program, which enters from the keyboard a one-dimensional array of N integers (the number N
    is entered from the keyboard), then displays the number of non-zero elements of the array. Front
    entering each item on the screen should display a tooltip with the item number. HELP ME PLEASE

  6. Write a program, which enters from the keyboard 10 real numbers, organizes their storage in an array and determines the difference between the maximum and minimum element of the array

    1. const int length = 10;
      int numbers[length];
      int min = 0;
      int max = 0;
      int difference;

      for (size_t i = 0; i < length; i )
      {
      cout << "Enter number " << i + 1 <> numbers[i];
      }

      for (size_t i = 0; i < length; i )
      {

      cout << numbers[i] << " ";

      }

      min = numbers[0];
      max = min;
      for (int i = 1; i max) max = numbers[i];
      if (numbers[i] < min) min = numbers[i];
      }
      cout << "Min: " << min << endl;
      cout << "Max: " << max << endl;
      difference = max – min;
      cout << "Difference = " << difference << endl;

      1. const int length = 10;
        int numbers[length];
        int min = 0;
        int max = 0;
        int difference;

        for (size_t i = 0; i < length; i )
        {
        cout << "Enter number " << i + 1 <> numbers[i];
        }

        for (size_t i = 0; i < length; i )
        {

        cout << numbers[i] << " ";

        }

        min = numbers[0];
        max = min;
        for (int i = 1; i max) max = numbers[i];
        if (numbers[i] < min) min = numbers[i];
        }
        cout << "Min: " << min << endl;
        cout << "Max: " << max << endl;
        difference = max – min;
        cout << "Difference = " << difference << endl;

Leave a Reply

Your email address will not be published. Required fields are marked *