hello_word.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <iostream>
  2. using namespace std;
  3. #define sqr(x) x * x
  4. // #define MAX(a, b, c) ((a) >= (b)) ? (c) = (a) : (c) = (b);
  5. #define MAX(x, y, r) {typeof(x) _x = x; typeof(y) _y = y; \
  6. (r) = (_x >= _y ? _x : _y);}
  7. void sum();
  8. void out_stream();
  9. void in_stream();
  10. void in_stream_get();
  11. int power(int x, unsigned p);
  12. int main()
  13. {
  14. std::cout << "Hello, World!\n";
  15. int c = 0;
  16. // sum();
  17. // out_stream();
  18. // in_stream();
  19. // in_stream_get();
  20. #if 0
  21. int ret = power(5, 2);
  22. std::cout << "res = " << ret << "\r\n";
  23. ret = power(5, 0);
  24. std::cout << "res = " << ret << "\r\n";
  25. #endif
  26. // std::cout << sqr(3 + 0) << "\r\n";
  27. MAX(4, 6, c);
  28. std::cout << c << "\r\n";
  29. return 0;
  30. }
  31. //
  32. void sum()
  33. {
  34. int a = 0;
  35. int b = 0;
  36. cout << "Enter a and b: ";
  37. cin >> a >> b;
  38. cout << "a + b = " << (a + b) << endl;
  39. }
  40. // in/out streams
  41. void out_stream()
  42. {
  43. int i = 42;
  44. double d = 3.14;
  45. const char *s = "C-style string";
  46. std::cout << "This is integer " << i << "\r\n";
  47. std::cout << "This is double " << d << "\r\n";
  48. std::cout << "This is a \"" << s << "\"\n";
  49. }
  50. void in_stream()
  51. {
  52. int i = 42;
  53. double d = 3.14;
  54. std::cout << "Enter an integer and a double:\r\n";
  55. std::cin >> i >> d;
  56. std::cout << "Your input is " << i << ", " << d << "\r\n";
  57. }
  58. void in_stream_get()
  59. {
  60. char c = '\0';
  61. while (std::cin.get(c)) {
  62. if (c != 'a')
  63. std::cout << c;
  64. else break;
  65. }
  66. }
  67. int power(int x, unsigned p)
  68. {
  69. return (!p) ? 1 : x * power(x, p - 1);
  70. }