This is a C# Program to find magnitude of integer.
This C# Program Finds Magnitude of Integer.
Here Magnitude of an integer is nothing but the length of the integer which is obtained using the mod function.
Here is source code of the C# Program to Find Magnitude of Integer. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Find Magnitude of Integer */ using System; public class Program { public static void Main() { int num, mag=0; Console.WriteLine("Enter the Number : "); num = int.Parse(Console.ReadLine()); Console.WriteLine("Number: " + num); while (num > 0) { mag++; num = num / 10; }; Console.WriteLine("Magnitude: " + mag); Console.Read(); } }
In this C# program, we are reading a number using ‘num’ variable. Using While loop check the value of ‘num’ variable is greater than 0. If the condition is true then execute the statement and compute the magnitude of integer. Magnitude of an integer is nothing but the length of the integer which is obtained using the mod function. Print the magnitude of integer.
Enter the Number : 3145678 Number : 3145678 Magnitude : 7
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Apply for Computer Science Internship
- Check Computer Science Books
- Practice MCA MCQs
- Apply for C# Internship
- Practice Computer Science MCQs