我的代码正在显示数组。如何显示给定整数的重复次数并显示重复的下标位置?在二维数组中计数并显示出现
#include <iostream>
#include <cmath>
#include <iomanip>
#include <ctime>
using namespace std;
int main()
{
int table [10][10]={{0},{0}};
int repeat=0;
int count=0;
int r=0;
int c=0;
//seeding the random function
srand(static_cast<int>(time(0)));
for(r=0; r<10; r++)//row
{
for(c=0; c<10; c++)
{
table[r][c] = 50+rand() %(100-50+1);
cout << table[r][c]<<" ";
}
cout<<endl;
}
cout<<"Enter the number to know how many times it is repeated(50 to 100): ";
cin>>repeat;
for (int x=0; x<10; x++)
{
if(repeat==table[r][c])
count+=1;
}
cout<<"the number "<<repeat<<" appeared"<<count<<" times."<<endl;
//display new line
system("pause");
}
而你的问题是? – 2010-11-10 06:27:55
如何编码以显示给定整数重复的次数,并显示重复的下标位置? – Luckwhy 2010-11-10 06:31:15
这是一个功课题吗? – 2010-11-10 06:39:46