Thursday 19 June 2014

C++ program to print the abundant numbers from 1 to n


Here is a C++ program to print the abundant numbers from 1 to n


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    long sum=0,n;
    cout<<"Enter the value of n ";
    cin>>n;
    for(int y=1;y<=n;y++)
    {
      for(int i=1;i<y;i++)
      {
          if(y%i==0)
             sum+=i;
      }
      if(sum>y)
        cout<<y<<" ";
      sum=0;
    }
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment