/* * basics.cpp * * Created on: 11.10.2012 * Author: trifon */ #include #include #include using namespace std; int main2() { /* cout << 0x3D << ' ' << 017 << '$' << '\''; cout << '\\' << '\t' << 'a' << '\n' << 'z'; cout << " test " << "про\nба"; cout << "" << "" << "" << "" << "<"; cout << (2 + 3)/7 << 4 + 5; // едноредов коментар /* многоредов коментар ! */ /* 2 + 3; cout << 25 << endl << endl; */ int a, b, c; cout << "Моля, въведете a и b: "; cin >> a >> b; c = sqrt(a*a + b*b); cout << "a = " << a << endl; cout << "b = " << b << endl; cout << "c = " << c << endl; const int N = 2; cout << "Константата N = " << N << endl; // грешка: N = 3; // cin >> N; cout << "N + 5 = " << N + 5 << endl; // cout << "abc" / 3 << endl; //char x[] = "abc"; // cout << x / 3 << endl; bool p = true, q = false; p = false; cout << "Резултатът е " << (p && !q) << endl; cout << "p заема " << sizeof(p) << " байта в паметта" << endl; cout << "Моля, въведете q: "; cin >> q; cout << "Вие въведохте: " << q << endl; char ch = 'A'; ch = 120; cout << "Символът ch e " << ch << endl; cout << "Моля, въведете нова стойност на ch: "; cin >> ch; cout << "Символът ch вече e " << ch << endl; unsigned char ch2 = 240; cout << "Символът ch2 е " << ch2 << endl; return 0; } int main3() { int a, b; cout << "Моля, въведете a и b: "; cin >> a >> b; cout << "Частното на a и b е: " << a/b << endl; cout << "Остатъкът на a при деление на b е: " << a%b << endl; cout << "Вярно ли е, че a = b? " << (a == b) << endl; unsigned c = -5; cout << "c = " << c << endl; cout << 12e-2 << endl; cout << 1000000000.0 << endl; //cout << 1.2 % 3.4 << endl; cout << 1.2 / 3.4 << endl; float f = 1.8; f = f - 0.3; f = f - 0.3; f = f - 0.3; f = f - 0.3; f = f - 0.3; cout << f << endl; cout << (f == 0.3) << endl; double const EPS = 1E-4; cout << (fabs(f - 0.3) < EPS) << endl; return 0; } int main() { bool b = false; char c = 'x'; short s = 319; int i = 1414512; long l = 12318309819; float f = 1.5; double d = 1.53948298493; // c = b; // s = c; // i = s; // l = i; // !!! f = l; // d = f; // b = c; // !!! c = s; // !!! s = i; // !!! i = l; // !!! l = f; // !!! f = d; cout << setprecision(12); cout << "b = " << b << endl; cout << "c = " << c << endl; cout << "c's ASCII code = " << (double)c << endl; cout << "s = " << s << endl; cout << "i = " << i << endl; cout << "l = " << l << endl; cout << "f = " << f << endl; cout << "d = " << d << endl; cout << "abs(-5) = " << abs(-5) << endl; cout << "abs(-5.23) = " << abs(-5.23) << endl; cout << "5/3 = " << (float)5/(double)3 << endl; cout << (s < l); return 0; }