zoukankan      html  css  js  c++  java
  • PTA 6-9 统计个位数字 (15分)

    这题的解决方法和保存1000!的方法类似,核心代码是j = i % 10,i /= 10;

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    
    int Count_Digit(const int N, const int D);
    
    int main()
    {
        int N, D;
    
        scanf("%d %d", &N, &D);
        printf("%d
    ", Count_Digit(N, D));
        return 0;
    }
    
    int Count_Digit(const int N, const int D) {
        int i = N > 0 ? N : -N; // 对N取绝对数
        int j = 0, b = 0;       // b用来统计出现D的次数,i/10= j,j用来保存结果
        do
        {
            j = i % 10;
            if (j == D)
                b++;
            i /= 10;
        } while (i > 0);
        return b;
    }
  • 相关阅读:
    URL
    B/S架构
    SQL查询语句
    SQL-Delete语句
    SQL运算符
    SQL结构查询语言
    SQL数据库数据类型详解
    标准文档流
    CSS
    字体样式
  • 原文地址:https://www.cnblogs.com/letwant/p/14277711.html
Copyright © 2011-2022 走看看