Prints 1 to the maximum number of n digits//input number n, in order to print out from 1 to the largest n decimal digits. For example: Enter 3, then print out 1, 21 until the maximum 3 digits 999#include <stdio.h> #include <stdlib.h> #include <memory.h>int num[10]; int add (int n) {int isoverflow = 0;int carry = 0;int i;for (i = 9; I >= 10-n; i--) {Num[i] + = carry;if (i = = 9) num[i]++ if (Num[i] >=) {if (i = = 10-n) {isoverflow = 1;} Else{num[i]-= 10;carry = 1;}} Else{break;}} return isoverflow;} int main (void) {int n, i;while (scanf_s ("%d", &n)! = EOF && n >= 1 && n <= 5) {memset (&num, 0, sizeof (int) *), while (!add (n)) {int flag = 0;for (i = 10-n; I < i++) {if (num[i]! = 0 | | flag) //If the previous 0, do not lose 0, the output {flag = 1;printf ("%d", Num[i]);}} printf (" ");}} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"C" Prints 1 to the maximum number of n digits