Computer Science, asked by lotussujith3938, 9 months ago

Write a program to find the factor of 8 and its sum of factors using while loop. 8=1,2,4,8. sum =15.

Answers

Answered by Yamini1999
0

Answer:

#include <iostream>

using namespace std;

int main()

{

 int n,i = 1,sum=0;  

 cin>>n;

 while (i <= n)

  {

    if(n%i == 0)

     {

         cout<<i<<"\n";  

         sum=sum+i;

         }

   i++;

  }

    cout<<"Sum is "<<sum<<"\n";  

 return 0;

}

Explanation:

Similar questions