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

📄 ex0615.cpp

📁 《C++编程习题与解答》书中所有例题与习题的源代码
💻 CPP
字号:
//  Programming with C++, Second Edition, by John R. Hubbard
//  Copyright McGraw-Hill, 2000
//  Example 6.15 on page 136
//  Testing an array for monotonicity

#include <iostream>
using namespace std;

bool isNondecreasing(int a[], int n);
// returns true iff a[0] <= a[1] <= ... <= a[n-1];

int main()
{ // tests the isNondecreasing() function:
  int a[] = { 22, 44, 66, 88, 44, 66, 55 };
  cout << "isNondecreasing(a,4) = " << isNondecreasing(a,4) << endl;
  cout << "isNondecreasing(a,7) = " << isNondecreasing(a,7) << endl;
}

bool isNondecreasing(int a[], int n)
{ // returns true iff a[0] <= a[1] <= ... <= a[n-1]:
  for (int i=1; i<n; i++)
    if (a[i]<a[i-1]) return false;
  return true;
}

⌨️ 快捷键说明

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