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

📄 numword.h

📁 The source code samples for chapter 2, 4, 6, and 8 are contained in the EvenChapters project. Those
💻 H
字号:
// NumWord.h

#pragma once
#ifndef _NUMWORD_H_
#define _NUMWORD_H_

inline
char* NumWord(long n, char* psz)
{
  *psz = 0;

  if( n < 0 )
  {
    n *= -1;
    strcpy(psz, "minus ");
  }

  long  billions = n/1000000000;
  if( billions )
  {
    n %= 1000000000;
    NumWord(billions, psz + strlen(psz));
    strcat(psz, " billion");
  }

  long  millions = n/1000000;
  if( millions )
  {
    n %= 1000000;
    if( *psz ) strcat(psz, ", ");
    NumWord(millions, psz + strlen(psz));
    strcat(psz, " million");
  }

  long  thousands = n/1000;
  if( thousands )
  {
    n %= 1000;
    if( *psz ) strcat(psz, ", ");
    NumWord(thousands, psz + strlen(psz));
    strcat(psz, " thousand");
  }

  long  hundreds = n/100;
  if( hundreds )
  {
    n %= 100;
    if( *psz ) strcat(psz, ", ");
    NumWord(hundreds, psz + strlen(psz));
    strcat(psz, " hundred");
  }

  long  tens = n/10;
  if( tens > 1 )
  {
    n %= 10;
    static const char* rgpszTens[] = { "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
    if( *psz ) strcat(psz, " and ");
    strcat(psz, rgpszTens[tens - 2]);
  }

  if( n )
  {
    static const char* rgpszTeens[] = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
    if( *psz && n && tens <= 1 ) strcat(psz, " and ");
    else if( *psz && n ) strcat(psz, " ");
    strcat(psz, rgpszTeens[n]);
  }
  else if( !*psz )
  {
    strcpy(psz, "zero");
  }

  return psz;
}

#endif  // _NUMWORD_H_

⌨️ 快捷键说明

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