user18042745
user18042745

Reputation:

How to remove extra space in output of code?

Help! I am trying to print my code is giving the correct output BUT with an extra space that is not supposed to be there.

   for (int i = i; i <= input; i++)
   {
        cout << factorial(input)/ (factorial(i) * factorial (input - i)) << " ";
   }
   return 0;
}

Upvotes: 0

Views: 280

Answers (1)

pm100
pm100

Reputation: 50190

Dont pad with space at the end on the last element

   for (int i = 1; i <= input; i++)
   {
        cout << factorial(input)/ (factorial(i) * factorial (input - i));
        if(i < input)
          cout << " ";
   }

Upvotes: 1

Related Questions