1)создать массив размером 10! заполнить его рандомными числами! вывести максимальное число 2)создать программу решения квадратного уровнения 3)создать игру угодай число! в конце вывести число попыток! и сумму всех чисел!

elenalenam elenalenam    3   03.09.2019 05:30    0

Ответы
skata9196 skata9196  06.10.2020 14:00
#1:
#include <iostream>
#include <ctime>

int main()
{
  srand(time(NULL));

  const int arraySize = 10;
  int mainArray[arraySize];  
  
  for (int i = 0; i < arraySize; i++)
    mainArray[i] = rand() % 1000;
  
  int maxNum = mainArray[0];
  for (int i = 0; i < arraySize; i++)
    if (mainArray[i] > maxNum)
      maxNum = array[i];
  
  std::cout << maxNum << std::endl;

  system("pause");
  return 0;
}

#2:
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  float
    a_coef,
    b_coef,
    c_coef;

  cout << "Input the coefficients (a * x^2 + b * x + c): ";
  cin >> a_coef >> b_coef >> c_coef;
  
  float res1, res2;
  
  res1 = (-b_coef + sqrt(b_coef * b_coef - 4 * a_coef * c_coef)) / (2 * a_coef);
  res2 = (-b_coef - sqrt(b_coef * b_coef - 4 * a_coef * c_coef)) / (2 * a_coef);
  
  cout << res1 << "; " << res2 << endl;

  system("pause");
  return 0;
}

#3:
#include <iostream>
#include <ctime>

int main()
{
  srand(time(NULL));
  int
    unknownNumber = rand() % 100 - 50,
    attempts = 0,
    inputtedNumber;

  while (true)
  {
    attempts++;

    cout << "Input the number: ";
    cin >> inputtedNumber;
    
    if (inputtedNumber != unknownNumber)
      cout << "Incorrect answer! Try again!" << endl;
    else
      break;
  }

  cout << "Attempts: " << attempts;
  
  system("pause");
  return 0;
}
ПОКАЗАТЬ ОТВЕТЫ
Другие вопросы по теме Информатика