Pages

Wednesday, 20 August 2014

Digital Roots Program in C++

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int i,j,c=0,n,k,l,x,f=0;
    cout<<"Type range Of numbers U want To enter"<<endl;
    cin>>n;
    cout<<endl;
    for(i=1;i<=n;i++)
    {
        c=c+i;
    }
    cout<<"The sum is :: "<<c<<endl;
    if(c>9)
    {
     n=c;
     cout<<"The value of n is : "<<n<<endl;
     while (n>0)
        {
     f+= n% 10;
     cout<<"f is "<<f<<endl;

     n= n/10;
     if (n == 0 && f > 9) { n = f; f = 0; }

     cout<<"The value of n is : "<<n<<endl<<endl;
        }
     }
     cout<<"The new  Digital root is  "<<f<<endl;
}



output:
ouput for range of 35 number u can enter any range u want

0 comments:

Post a Comment

 

Blogger news

Blogroll