prog2_02.cpp

来自「一本语言类编程书籍」· C++ 代码 · 共 25 行

CPP
25
字号
// Program 2.2 - Working with integer variables
#include <iostream>              // For output to the screen
using std::cout;
using std::endl;

int main() {  
  int apples = 10;             // Definition for the variable apples
  int children = 3;            // Definition for the variable children

  // Calculate fruit per child
  cout << endl                   // Start on a new line
       << "Each child gets "     // Output some text
       << apples/children        // Output number of apples per child
       << " fruit.";             // Output some more text

  // Calculate number left over
  cout << endl                   // Start on a new line
       << "We have "             // Output some text
       << apples % children      // Output apples left over
       << " left over.";         // Output some more text

  cout << endl;
  return 0;                      // End the program
}

⌨️ 快捷键说明

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