Пример #1
0
int main(){
  unsigned long n = 100;
  unsigned long sol=0;
  sol=squareSum(n)-sumSquare(n);
  printf("%lu - %lu = %lu\n",squareSum(n),sumSquare(n),sol);
  return 0;
}
Пример #2
0
void problem6(void) {
	printf("Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.\n");
	int summation = sum(0,100);
	int sumSqr = sumSquare(0,100);
	int result = (summation * summation) - sumSqr;
	printf("Result: %d", result);
}
Пример #3
0
/*!
  Normalise the vector modifying the vector as:

  \f[
  {\bf x} = \frac{{\bf x}}{\sqrt{\sum_{i=1}^{n}x^2_i}}
  \f]
  where \f$x_i\f$ is an element of the row vector \f$\bf x\f$.
*/
vpRowVector &vpRowVector::normalize()
{
  double sum_square = sumSquare();
  if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
    *this /= sqrt(sum_square) ;
  }

  // If sum = 0, we have a nul vector. So we return just.
  return *this;
}
Пример #4
0
/*!
  \relates vpColVector
  \brief normalise the vector

  \f[
  {\bf x}_i = \frac{{\bf x}_i}{\sqrt{\sum_{i=1}^{n}x^2_i}}
  \f]
*/
vpColVector &vpColVector::normalize()
{

  double sum = sumSquare() ;

  if (sum != 0.0)
    *this /= sqrt(sum) ;

  // If sum = 0, we have a nul vector. So we return just.
  return *this;
}
Пример #5
0
/*!
  \relates vpColVector
  \brief normalise the vector

  \f[
  {\bf x}_i = \frac{{\bf x}_i}{\sqrt{\sum_{i=1}^{n}x^2_i}}
  \f]
*/
vpColVector &vpColVector::normalize()
{

  double sum = sumSquare() ;

  //if (sum != 0.0)
  if (std::fabs(sum) > std::numeric_limits<double>::epsilon())
    *this /= sqrt(sum) ;

  // If sum = 0, we have a nul vector. So we return just.
  return *this;
}
Пример #6
0
int main(int argc, char *argv[]) {

  bigInt simsum, sqrsum, result, top, bottom;
  bottom = 1;
  top = 100;
  simsum = sum(bottom, top);
  sqrsum = sumSquare(bottom, top);

  result = square(simsum) - sqrsum;

  printf("This is the of %lu - %lu: %lu\n", square(simsum), sqrsum, result);

}
Пример #7
0
int main(int argc, char *argv[])
{
    std::ifstream in(argv[1]);
    std::string num;
    int tmp;
    while(getline(in,num)) //read line, to avoid EOF problem
    {
        std::set<int> a;//set stores unique elements
        //better a for loop with some large number, than risk an infinite loop with while(1)
        for(int i = 0; i < 20; ++i)
        {
            tmp = sumSquare(num);
            if(tmp == 1)
            {
                //if sum of squares is 1 then the number is happy
                std::cout << "1" << std::endl;
                //end for loop
                break;
            }
            //if tmp!= 1 then add tmp to set "a"
            auto ret = a.emplace(tmp);
            //if ret==false, tmp is already in set, number is not happy
            if (!ret.second)
            {
                //number is not happy
                std::cout << "0" << std::endl;\
                //end for loop
                break;
            }
            //convert tmp to string because function sumSquares accepts a string
            num = std::to_string(tmp); //this could have been avoided
        }

    }
    return 0;
}
Пример #8
0
int main()
{
	std::cout << squareSum(100) - sumSquare(100) << std::endl;
}
double TransformErrFunction::cParamVals::frobeniusNorm() const
{
    return sqrt(sumSquare());
}