C# program to find the magnitude of an integer number
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to find the magnitude of an integer number in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a class MagnitudeDemo that contains GetMagnitude() and Main() methods. The GetMagnitude() method returns the magnitude of the specified number.
Here we divide the number by 10 till it becomes 0. In every iteration of while loop we increase the value of magnitude variable by 1 and reduce the number num by 1 digit in length.
In the Main() method, we created an integer variable num initialized with 34521 and then pass the variable in the static method GetMagnitude() and get the magnitude in local variable mag and then printed the value of mag on the console screen.