Write a program in c++ to print the sum and product of digits of an integer

 Write a program in c++ to print the sum and product of digits of an integer.

#include <iostream>
using namespace std;
int main()
{
    int nnumldigitsumproduct = 1;
    cout << "Enter A Number : ";
    cin >> num;
    n = num;
    while (num != 0)
    {
        ldigit = num % 10;
        sum = sum + ldigit;
        product = product * ldigit;
        num = num / 10;
    }

    cout << "Sum of digit of " << n << " = " << sum;
    cout << "\nProduct of digit of " << n << "= " << product;
    return 0;
}


OUTPUT OF PROGRAM

Enter A Number : 4976
Sum of digit of 4976 = 26     
Product of digit of 4976= 1512



Share:

0 Comments:

Post a Comment

Pageviews