WAP to print the sum and product of digits of an integer.



#include<iostream.h>
#include<conio.h>
class dig
{
public:
void m();
}   ;

void dig::m()
{
int n;
clrscr();
cout<<"enter the number whose sum and products of digits has to be found out"<<endl;
cin>>n;
int sum,pro;
sum=0;
pro=1;
                                  while(n>0)
                                  {
                                  int a=n%10;
                                  sum=sum+a;
                                  pro=pro*a;
                                  n=n/10;
                                  }
cout<<"the sum is "<<sum<<" and the product is "<<pro<<endl;
}

void main()
{
dig obj;
obj.m();
getch();
}


Output:-


Comments