Skip to content

Instantly share code, notes, and snippets.

@Abreto
Created October 4, 2012 16:15
Show Gist options
  • Save Abreto/3834680 to your computer and use it in GitHub Desktop.
Save Abreto/3834680 to your computer and use it in GitHub Desktop.
用语言描述的三位数
/* Program E6.1 - print nature language for a number. */
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char map[][4] = {"零","一","二","三","四","五","六","七","八","九"};
int num = 0;
printf("Please enter a three-digit number: ");
scanf("%d", &num);
if( (num/10) % 10 == 0 )
printf("%s百零%s\n", map[ (num/100) % 10 ], map[ num % 10 ]);
else
printf("%s百%s十%s\n", map[ (num/100) % 10 ], map[ (num/10) % 10 ], map[ num % 10 ]);
return 0;
}
@Abreto
Copy link
Author

Abreto commented Oct 5, 2012

忘了个位为零的情况

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment