Write C++ program to calculate product of digits of a number


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int num, product=1;
  9.  
  10. //Reading a number from user
  11. cout<<"Enter any number:";
  12. cin>>num;
  13.  
  14. // Repeat the steps till n becomes 0
  15. while(num != 0)
  16. {
  17. product = product * (num % 10);
  18.  
  19. // Remove the last digit from n
  20. num = num / 10;
  21. }
  22.  
  23. cout<<"Product of digits: "<<product;
  24.  
  25. return 0;
  26. }
  27.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts