Analyzing a -20200403- a daily problem several of integer data integer data from a keyboard (int type), and outputs each comprising a number of digits.

Analyzing several of a integer data
from a keyboard input data integer (int type), and a switch statement written in the program loop determines whether the total of several integer, and each output contains the number of digits. For example, from the keyboard 16644 integers which total an integer of 5, including 1 1,2 6,2 4 months.

Example result of the program. 1:
12226↙
12226:. 5 bits
. 1:. 1
2:. 3
. 6:. 1

Result of the program Example 2:
Please Enter The Number:
-12243↙
-12 243:. 5 bits
. 1:. 1
2: 2
. 3:. 1
. 4:. 1

Input format: "% d"
Output Format:
Input message: "Please enter the number: \ n"
Analyzing several of the Integer Total: "% d:% d bits \ n"
contains the number of the numbers 0: "0: "% d \ n
the number of figures 1 comprising:" 1:% d \ n "
contains the number of the number 2:" 2:% d \ n "
contains the number 3 in number:" 3:% d \ n "
4 comprises a digital number: "4:% d \ n "
number of figures 5 comprising: "5:% d \ n "
contains the number of figures 6: "6:% d \ n "
contains a number of 7 number: ". 7:% D \ n-"
: "% D \ n-8:" contains the number of the number 8
the number of the number 9: "9:% d \ n "

#include <stdio.h>
#include <math.h>
int main ( )
{
    printf("Please enter the number:\n");
    int num,d,j = 0,a[10]= {0},c,sum = 0;
    scanf("%d",&num);
    if(num < 0) c = fabs(num);
    else c = num;
    while(1)
    {
 	   d = c % 10;
        a[d]++;
        c /= 10;
        sum++;
        if (c == 0) break;
    }
    printf("%d: %d bits\n",num,sum);
    for (j = 0; j < 10; j++) {
        if(a[j] != 0)
            printf("%d: %d\n",j,a[j]);
    }
    
}

Ideas:
a required subject ·
1 · judge Several
2-seeking several times each number appears
two-thinking
judge Several times in fact, can occur by summing get each digital
watch digital appear on every several prior methods required by the digit num% 10 = bits;
(:) loop
to each have become like bits
num / 10; num / 100; num / 1000
final EG
NUM / 10000000 = 0, it means that the count over the count, the end of cycle

In fact, according to their own ideas to determine the loop, not the same as the end of the loop, there is not the same conditions.

Published 18 original articles · won praise 0 · Views 198

Guess you like

Origin blog.csdn.net/weixin_46456339/article/details/105303312