Find the SUM of Digit of a Number

Program:


    #include<iostream.h>
    #include<conio.h>
class sumdigit { public: int add(int); }; int sumdigit::add(int(num) { if(num<=9) return(num); else return(num%10+add(num%10)); } void main() { sumdigit ob; int num,sum; clrscr(); cout<<"Enter the Positive integer \n"; cin>>num; sum=ob.add(num); cout<<"\nSum of Digits of "<<num<<" = "<<sum; getch(); }
Powered by nasrullah.in - TechnoNasr 2003-2020.
Designed & Developed by Mohamed Nasrullah.M