我家丫头的cpp

C语言 计数0-9各出现了多少次

2019-03-28  本文已影响0人  李药师_hablee
//计数0-9各出现了多少次
#include<stdio.h>
#include<stdlib.h>

int main()
{
    const int number = 10;
    int i,x;

    int a[number] = { 0 };//数组初始化
    printf("input x:\n");
    scanf_s("%d", &x);
    while (x != -1)
    {
        a[x]++;
        scanf_s("%d", &x);
    }

    for (i = 0; i < 10; i++)
    {
        printf("%d: %d次\n", i, a[i]);
    }
    
    system("pause");
    return 0;
}

输出

输出.PNG

本程序在visual studio 2017下编译运行

上一篇 下一篇

猜你喜欢

热点阅读