⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex3_01.cpp

📁 一本语言类编程书籍
💻 CPP
字号:
//  Exercise 3.1 The potential for trouble here comes in the statement that calculates the reciprocal.
// If you write it as 1/denominator, the program won't work - integer division will take place,
// and the output will (nearly) always be 0. The solution is to write the literal as 1.0, 
// which is of type double, so that the division is carried out correctly.

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main() {
  int denominator = 0;
  double reciprocal = 0;

  cout << "Enter a non-zero integer, and I'll calculate its reciprocal: ";
  cin >> denominator;

  reciprocal = 1.0/denominator;

  cout << "The reciprocal of " << denominator << " is " << reciprocal << endl;
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -