C language Output 1-n-bit maximum integer

Source: Internet
Author: User

/*1. Print 1 to the maximum number of n digits. Title: Enter the number n, in order to print out from 1 to the largest number of n decimal digits. For example: Enter 3, then print out 1, 2, 31 until the maximum 3 digits 999. [Trap]: The easiest way to think about this topic is to find the maximum number first. Then the loop output is ready. */#include <stdio.h>//think of the method, from a[0]-a[n] sequentially output each bit, one output only one bit of a number Int main () {int i = 0,j  = 0,k = 0,input=3;//i for the control carry   j for each bit output (bit, 10 bits, etc.)//k for loop carry,input  for maximum output number char  a[] =  "100000000";//Analog Carry Storage while  (J < input)//Determine whether to end {while  (j >= &NBSP;0)//control output of a bit {printf ("%c", A[j]);//output one digit if  (j == 0)  //j==0 for bits   increments {if  (a[j ] ==  ' 9 ')//digit 9 {for  (k = 0; k < input;)//Whether multiple carry {if  (A[k+1] < ' 9 ') {a[k + 1]++;a[k] =  ' 0 ';if  (a[k + 1] ==  ' 1 ' &&i< k+1) i++;//opens a new number of digits break;} else{a[k] =  ' 0 ';//single-digit 0 k++;}}} elsea[0]++;//}j--;//j  from high   down}printf (" ")  //split   each number j = i;//let J be the current highest bit   For example  10  j=i=1;}return 0 after:9 ;} #include<stdio.h> #include <string.h> #include <assert.h>int add_num (Char *arr,int num, int end)//Online general logic analog Digital accumulation program (slightly different) {                                       //num   output digits n  end   analog space Max assert (arr); int is_carry = 0;//whether carry int is_over = 1;//is exceeded with overflow int i = end-1; char *arr1 = arr;if  (arr1[i] != 9) {arr1[i]++;} else{is_carry = 1;arr[i] = 0;while  (1) {if  (end-1 -  (i - 1)  >= num | |  i == 0) {printf ("\n   ****   output ends!  ****\n "); is_over = 0;return is_over;} if  (arr1[--i] != 9) {arr1[i] += is_carry;is_carry = 0;break;} else{arr1[i] = 0;}}}} Void show_num (Char *arr,int num)//Bitwise output {int is_high = 0;while  (num>0) {if   (*arr == 0&&is_high==0) arr++;else{printf ("%d", (int) *arr++); is_high = 1;} num--;} printf (" ");} Int main () {char num[11] = {  '  };while  (Add_num (num, 3,11)) {Show_num (num,11);} return 0;}


C language Output 1-n-bit maximum integer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.