#include <iostream>
using std::cout;
using std::endl;
using std::fixed;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
#include <iomanip>
using std::setprecision;
int main()
{
float a[16];
float counter = 0;
srand(time(0));
for(int i = 0; i < 16; i++)
{
a[i] = float(rand()) / RAND_MAX * (3.0 + 2.0) - 2.0;
if(a[i] < 0.0)
{
counter += a[i];
}
cout << setprecision(2) << fixed << a[i] << endl;
}
cout << endl;
cout << "Sum = " << counter << endl;
return 0;
}
#include <iostream>
#include <windows.h>
char BufRus[256];
char* Rus(const char* text)
{
CharToOem(text, BufRus);
return BufRus;
}
using namespace std;
int main()
{
float a[16];
for(int i=0;i<16;i++) a[i]=((float)(rand()%501))/100.0f-2;
float b=0;
int c=0;
for(int i=0;i<16;i++)
{
if(a[i]<0)
{
b+=a[i];
c++;
}
}
cout<<Rus("Сумма отр. чисел:")<<b<<endl;
cout<<Rus("Вего отр. элементов:")<<c<<endl;
cout<<Rus("Исходный массив:")<<endl;
for(int i=0;i<16;i++)
{
cout<<a[i]<<endl;
}
system("PAUSE");
return 0;
}
/*
фунция rand() возращает случайное число от 0 до бесконечности.
a%b - остаток от деления числа a на число b.
rand()%501 - случайное число от нуля до 500.
(float)x - преопразование x в тип float.
*/
Поделитесь своими знаниями, ответьте на вопрос:
які імена може скласти користувач з чотирьох символів: c, d, 8, _?
Вот все возможные варианты:
║ cd8_ ║ cd_8 ║ c8d_ ║ c8_d ║ c_d8 ║ c_8d ║ dc8_ ║ dc_8 ║║ d8c_ ║ d8_c ║ d_c8 ║ d_8c ║ 8cd_ ║ 8c_d ║ 8dc_ ║ 8d_c ║║ 8_cd ║ 8_dc ║ _cd8 ║ _c8d ║ _dc8 ║ _d8c ║ _8cd ║ _8dc ║begin Arr('c', 'd', '8', '_').Permutations.Select(x->x.JoinToString).Print(' ║ ') end.