C# Program to Find the Magnitude of an Integer Number

Hello, friend today we are going to see clearly what we are going to see in the article C# Program to Find the Magnitude of an Integer Number. We hope you find this article very useful.

C# Program to Find the Magnitude of an Integer Number

C# Program to Find the Magnitude of an Integer Number

// Write a program to find the 
// magnitude of an integer number in C#.

using System;

public class MagnitudeDemo
{
    public static int GetMagnitude(int num)
    { 
        int magnitude=0;

        while(num>0)
        {
            magnitude++;
            num = num/10;
        }
        return magnitude;
    }
    public static void Main()
    {
        int num = 34521;
        int mag = 0;

        mag = GetMagnitude(num);

        Console.WriteLine("Magnitude: " + mag);
    }
}
Magnitude: 5
Press any key to continue . . .

Final Words

C# Program to Find the Magnitude of an Integer Number We hope you find the article useful and will see you in the next article.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment