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


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..


techstudy.org

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

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class csharpExercise
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. int num, product = 1;
  12.  
  13. // Reading number
  14. Console.Write("Enter any number: ");
  15. num = Convert.ToInt32(Console.ReadLine());
  16.  
  17. // Repeat the steps till n becomes 0
  18. while (num != 0)
  19. {
  20. product = product * (num % 10);
  21.  
  22. // Remove the last digit from n
  23. num = num / 10;
  24. }
  25.  
  26. Console.WriteLine("Product of digits = "+ product);
  27.  
  28. Console.ReadLine();
  29. }
  30. }

Result

C# language techstudy

     





Related Topics




Popular Posts