编一程序,统计矩阵中各个数字的出现次数。
已知二维数组dig[10][15]为一字符型矩阵,其每一元素为一数字字符(“0”,“1”,、、、“9”),编一程序,统计矩阵中各个数字的出现次数。...
已知二维数组dig[10][15]为一字符型矩阵,其每一元素为一数字字符(“0”,“1”,、、、“9”),编一程序,统计矩阵中各个数字的出现次数。
展开
2个回答
展开全部
#include <stdio.h>
int main()
{
char dig[10][15] =
{
{'0','1','1','2','4','6','5','9','6','4','7','0','6','1','3'},
{'5','9','6','4','7','0','6','1','3','6','5','9','6','6','4'},
{'4','9','6','4','1','3','6','7','0','6','1','3','6','5','3'},
{'5','0','6','1','3','6','5','9','0','1','1','2','4','0','5'},
{'6','1','3','6','0','6','1','3','6','5','9','0','0','6','1'},
{'2','3','6','7','3','6','0','6','1','6','5','9','1','1','7'},
{'6','6','3','6','7','3','6','0','6','1','6','7','0','9','1'},
{'8','1','3','6','6','0','6','9','1','1','7','6','5','9','8'},
{'8','1','3','6','6','0','8','1','3','6','0','6','1','1','1'},
{'0','6','4','7','0','6','1','3','3','6','7','3','6','0','1'}
};
char digit[] = "0123456789";
int count = 0;
for (int i=0; i<10; ++i)
{
for (int j=0; j<10; ++j)
{
for (int k=0; k<15; ++k)
{
if (dig[j][k] == digit[i])
{
++count;
}
}
}
printf("有%d个%c\n",count,digit[i]);
count = 0;
}
return 0;
}
//结果如下:
有19个0
有27个1
有3个2
有18个3
有8个4
有10个5
有41个6
有12个7
有4个8
有10个9
int main()
{
char dig[10][15] =
{
{'0','1','1','2','4','6','5','9','6','4','7','0','6','1','3'},
{'5','9','6','4','7','0','6','1','3','6','5','9','6','6','4'},
{'4','9','6','4','1','3','6','7','0','6','1','3','6','5','3'},
{'5','0','6','1','3','6','5','9','0','1','1','2','4','0','5'},
{'6','1','3','6','0','6','1','3','6','5','9','0','0','6','1'},
{'2','3','6','7','3','6','0','6','1','6','5','9','1','1','7'},
{'6','6','3','6','7','3','6','0','6','1','6','7','0','9','1'},
{'8','1','3','6','6','0','6','9','1','1','7','6','5','9','8'},
{'8','1','3','6','6','0','8','1','3','6','0','6','1','1','1'},
{'0','6','4','7','0','6','1','3','3','6','7','3','6','0','1'}
};
char digit[] = "0123456789";
int count = 0;
for (int i=0; i<10; ++i)
{
for (int j=0; j<10; ++j)
{
for (int k=0; k<15; ++k)
{
if (dig[j][k] == digit[i])
{
++count;
}
}
}
printf("有%d个%c\n",count,digit[i]);
count = 0;
}
return 0;
}
//结果如下:
有19个0
有27个1
有3个2
有18个3
有8个4
有10个5
有41个6
有12个7
有4个8
有10个9
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询