0

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;
}
  • Related to [idiom-for-iterating-between-each-consecutive-pair-of-elements](https://stackoverflow.com/questions/35372784/idiom-for-iterating-between-each-consecutive-pair-of-elements) – Jarod42 Jan 31 '22 at 09:42

1 Answers1

1

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 << " ";
   }
pm100
  • 48,078
  • 23
  • 82
  • 145