Получить и вывести на экран:
а) 10 случайных целых чисел, лежащих в диапазоне от 0 до 10
включительно;
б) k случайных целых чисел, лежащих в диапазоне от 0 до a
включительно. Значения k и a вводятся с клавиатуры;
в) 20 случайных целых чисел, лежащих в диапазоне от 10 до
20 включительно;
г) k случайных целых чисел, лежащих в диапазоне от –10 до a
включительно. Значения k и a вводятся с клавиатуры;
д) случайное натуральное k, не превосходящее 15, и k случайных целых чисел, лежащих в диапазоне от a до b включительно. Значения a и b вводятся с клавиатуры.
C/C++
Помогите решить задачки C++
#include <iostream>
#include <random>
#include <iomanip>
using namespace std;
class Random {
public:
Random() {
random_device device;
gen.seed(device());
gen_64.seed(device());
}
int next(int first, int last) {
uniform_int_distribution<int> range(first, last);
return range(gen);
}
double next(double first, double last) {
uniform_real_distribution<double> range(first, last);
return range(gen_64);
}
private:
mt19937 gen;
mt19937_64 gen_64;
};
int integer(const char* msg) {
cout << msg;
int value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
int main() {
system("chcp 1251 > nul");
Random rand;
auto k = 0, a = 0, b = 0;
puts(" Задача А: \n");
for (int i = 1; i <= 10; ++i) {
cout << setw(3) << i << ". " << rand.next(0, 10) << '\n';
}
puts("\n Задача Б: \n");
k = integer(" k: ");
do a = integer(" a: "); while (a <= 0);
puts("");
for (int i = 1; i <= k; ++i) {
cout << setw(3) << i << ". " << rand.next(0, a) << '\n';
}
puts("\n Задача В: \n");
for (int i = 1; i <= 20; ++i) {
cout << setw(3) << i << ". " << rand.next(10, 20) << '\n';
}
puts("\n Задача Г: \n");
k = integer(" k: ");
do a = integer(" a: "); while (a <= -10);
puts("");
for (int i = 1; i <= k; ++i) {
cout << setw(3) << i << ". " << rand.next(-10, a) << '\n';
}
puts("\n Задача Д: \n");
k = rand.next(1, 14);
a = integer(" a: ");
do b = integer(" b: "); while (b <= a);
cout << "\n k: " << k << '\n';
for (int i = 1; i <= k; ++i) {
cout << setw(3) << i << ". " << rand.next(a, b) << '\n';
}
system("pause > nul");
}
#include <random>
#include <iomanip>
using namespace std;
class Random {
public:
Random() {
random_device device;
gen.seed(device());
gen_64.seed(device());
}
int next(int first, int last) {
uniform_int_distribution<int> range(first, last);
return range(gen);
}
double next(double first, double last) {
uniform_real_distribution<double> range(first, last);
return range(gen_64);
}
private:
mt19937 gen;
mt19937_64 gen_64;
};
int integer(const char* msg) {
cout << msg;
int value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
int main() {
system("chcp 1251 > nul");
Random rand;
auto k = 0, a = 0, b = 0;
puts(" Задача А: \n");
for (int i = 1; i <= 10; ++i) {
cout << setw(3) << i << ". " << rand.next(0, 10) << '\n';
}
puts("\n Задача Б: \n");
k = integer(" k: ");
do a = integer(" a: "); while (a <= 0);
puts("");
for (int i = 1; i <= k; ++i) {
cout << setw(3) << i << ". " << rand.next(0, a) << '\n';
}
puts("\n Задача В: \n");
for (int i = 1; i <= 20; ++i) {
cout << setw(3) << i << ". " << rand.next(10, 20) << '\n';
}
puts("\n Задача Г: \n");
k = integer(" k: ");
do a = integer(" a: "); while (a <= -10);
puts("");
for (int i = 1; i <= k; ++i) {
cout << setw(3) << i << ". " << rand.next(-10, a) << '\n';
}
puts("\n Задача Д: \n");
k = rand.next(1, 14);
a = integer(" a: ");
do b = integer(" b: "); while (b <= a);
cout << "\n k: " << k << '\n';
for (int i = 1; i <= k; ++i) {
cout << setw(3) << i << ". " << rand.next(a, b) << '\n';
}
system("pause > nul");
}
a)
#include stdio.h
#include stdlib.h
#include time.h
int main(void){
srand(time(NULL));
int random;
random = printf("%d\n", rand()%10);
return 0;
}
#include stdio.h
#include stdlib.h
#include time.h
int main(void){
srand(time(NULL));
int random;
random = printf("%d\n", rand()%10);
return 0;
}
Похожие вопросы
- Помогите решить задачку c++.
- Помогите решить лабораторную c++
- Помогите пожалуйста решить задачки c++
- Помогите решить задачку по теме работа с файлами C++
- Помогите решить задачу c++
- Помогите решить задачу, c++, функции
- Помогите решить задачу C++
- Помогите решить задачу C++
- Помогите решить задачку пжпж условие на фото. Код необязателен, главное идею подскажите пжпж
- Помогите решить задачку по программированию