38 lines
1.3 KiB
C++
Executable File
38 lines
1.3 KiB
C++
Executable File
#include <iostream>
|
|
#include <cmath> // Функция pow
|
|
|
|
using namespace std;
|
|
|
|
int main() {
|
|
// Фундаментальные типы данных
|
|
|
|
// Numeric:
|
|
int myInt;
|
|
myInt = 5;
|
|
float myFloat = 6.23;
|
|
double myDouble = 6.2340282;
|
|
|
|
myInt = float(7) / 3; // Округляет вниз
|
|
cout << "Результат myInt = float(7)/3: " << myInt << endl; // 2
|
|
|
|
cout << "Результат 2+3*4: " << (2+3*4) << endl; // Тип integer, 14
|
|
cout << "Результат float(7)/3: " << float(7)/3 << endl; // Тип float, 2.33333
|
|
cout << "Результат 7/3: " << 7/3 << endl; // In C++ this is integer division, 2
|
|
cout << "Результат 7%3: " << 7%3 << endl; // Тип integer, 1
|
|
cout << "Результат 2^10: " << pow(2, 10) << endl; // Тип integer, 1024
|
|
cout << "Результат 2^100000: " << pow(2, 100000) << endl; // infinity?, inf
|
|
|
|
// Boolean
|
|
bool myBoolean;
|
|
// and - &&; or - ||; not - !;
|
|
|
|
// Character
|
|
char myCharacter = 'f'; // Single quotes (') for chars, double (") for strings
|
|
|
|
// Конвертация из одного типа в другой:
|
|
int origin = 50;
|
|
double origin_transformed = double(origin);
|
|
cout << "Преобразованная переменная: " << origin_transformed << endl;
|
|
|
|
return 0;
|
|
} |