Write a C# program to check whether a given substring is present in the given string

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..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
public class csharpExercise
{
    static void Main(string[] args)
    {
 
        int num, product = 1;
 
        // Reading number
        Console.Write("Enter any number: ");
        num = Convert.ToInt32(Console.ReadLine());
 
        // Repeat the steps till n becomes 0
        while (num != 0)
        {
            product = product * (num % 10);
 
            // Remove the last digit from n
            num = num / 10;
        }
 
        Console.WriteLine("Product of digits = "+ product);
 
        Console.ReadLine();
    }
}

Result

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

Add a Comment

Your email address will not be published. Required fields are marked *