title: Finding factors of number in C++ but I want to print number of factors on first line
body: <blockquote>
  <p><strong>I am able to find the factors but not getting how to print the
  count of factors like in Sample output in c++</strong></p>
  </blockquote>
  <p><strong>Question : You are given a number N and find all the distinct factors of N</strong></p>
  <p><strong>Input:</strong>
  First-line will contain the number N.</p>
  <p><strong>Output:</strong>
  In the first line print number of distinct factors of N.
  In the second line print all distinct factors in ascending order separated by space.</p>
  <p>Constraints
  1≤N≤10^6</p>
  <p>Sample Input 1:</p>
  <p>4</p>
  <p>Sample Output 1:</p>
  <p>3 //Number of factor</p>
  <p>1 2 4 //factors</p>
  <pre><code>  //My code
    #include&lt;bits/stdc++.h&gt;
    using namespace std;
    int main(){
     int n;
     cin&gt;&gt;n;
     int count =0;
     for(int i=1;i&lt;=n;i++){
      if(n%i == 0){
          count++;
          cout&lt;&lt;count&lt;&lt;endl;
          cout&lt;&lt;i&lt;&lt;&quot; &quot;;
         }
  }
  </code></pre>