比如我有两个Unsigned int 的变量count, step, step是步长等分,如何求出每个步长的长度例如count = 10, step = 310/3 = 3, 则依次3,3,4, 输出3,4这里都是unsigned int 类型,请各位大侠指点,谢谢

解决方案 »

  1.   

    就是实现这样的效果:
    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的结果不对,请问如何解决?
      

  2.   

    # include <iostream.h>
    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;
    }
    }运行过的,符合要求
      

  3.   

    我想了一个不是办法的办法:
    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;
    }
    }
    }各位大侠有何改进,谢谢
      

  4.   

    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时面的数据库
      

  5.   

    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++;
    }
    }