int count=10,step=3; int array[10]; int temp_const; int temp=0; for(int i=1;i<count;i++){ temp_const=i/step; if(temp_const!=array[temp-1]){ array[temp]=temp_const; temp++; } } 因为楼主没说很清楚,不知道我理解的对不. 是不是你的意思就是想要上面代码中 array时面的数据库
int count=10,step=3; int array[10]; int temp_const; int temp=0; for(int i=1;i<step;i++){ temp_const=(i*count)/step; if(temp_const!=array[temp-1]){ array[temp]=temp_const; temp++; } }
unsigned int count = 10;
unsigned int step = 3;
unsigned int num1 = 0;
unsigned int num2;
for(int i =1;i<=step;++i){
num2 = (i * count) / step; cout << num2 - num1 <<" ";
num1 = num2;
}
但是1/3,2/3的结果不对,请问如何解决?
main()
{
unsigned int count = 10;
unsigned int step = 3;
unsigned int num1 = 0;
unsigned int num2;
for(unsigned int i=1;i<=step;++i)
{
num2 = (i * count) / step; cout << num2 - num1 <<" ";
num1 = num2;
}
}运行过的,符合要求
void main()
{
unsigned int count = 14;//10;
unsigned int step = 15;
unsigned int num1 = 0;
unsigned int num2; if(count < step)
{
for(int j = 1; j <= step; ++j){ if (count != 0)
cout << 1<<" ";
else
cout<< 0 << " ";
if(count != 0)
count --;
} }
else
{
for(int i =1; i<=step; ++i){
num2 = (i * count) / step;
cout << num2 - num1 <<" ";
num1 = num2;
}
}
}各位大侠有何改进,谢谢
int array[10];
int temp_const;
int temp=0;
for(int i=1;i<count;i++){
temp_const=i/step;
if(temp_const!=array[temp-1]){
array[temp]=temp_const;
temp++;
}
}
因为楼主没说很清楚,不知道我理解的对不.
是不是你的意思就是想要上面代码中 array时面的数据库
int array[10];
int temp_const;
int temp=0;
for(int i=1;i<step;i++){
temp_const=(i*count)/step;
if(temp_const!=array[temp-1]){
array[temp]=temp_const;
temp++;
}
}