Saturday, November 26, 2016

Number of Digits in C#

Hi there in this article I would like to share with you a sample program that will ask the user to give a number and then our program will count how many digits that can be found in the given number by our user. The code uses while loop statement and it is very easy to understand and use.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output

Program Listing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace multiplication_table
{
    class multiplication_table
    {
        /* Program : Number of Digits                       */
        /* Author  : Mr. Jake R. Pomperada, MAED-IT         */
        /* Date    : Noverber 24, 2016  Thursday  10:12 AM  */
        /* Tools   : C#                                     */

        static void Main(string[] args)
        {

            int num=0,original_value=0, count_num = 0;
            Console.Write("\n\n");
            Console.Write("  ===== NUMBER OF DIGITS ===== ");
            Console.Write("\n\n");
            Console.Write("Give a Number : ");

            num= int.Parse(Console.ReadLine());

            original_value = num;
            while (num != 0)
            {
                num /= 10;
                count_num++;
            }
            Console.Write("\n\n");
            Console.WriteLine("The number of digits in {0} is {1}." ,original_value,count_num);
            Console.Write("\n\n");
            Console.Write("  End of Program ");
            Console.Write("\n\n");
            Console.ReadLine();
        }
    }
}



No comments:

Post a Comment