Basic Programming C# Examples

C# Program to find Strong Numbers within Range of numbers

The Program in C# Program to find Strong Numbers within Range of numbers is given below:

using System;

namespace Strong_Numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            int start, end, i, j, temp, rem, sum;
            Console.WriteLine("Hello Codeauri Family,enter the starting number of the range here: ");
            start = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Similarly, enter the ending number of the range: ");
            end = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Okay, the Strong Numbers in the given range are: ");
            for (i = start; i <= end; i++)
            {
                temp = i;
                sum = 0;
                while (temp > 0)
                {
                    rem = temp % 10;
                    sum = sum + Factorial(rem);
                    temp = temp / 10;
                }
                if (sum == i)
                {
                    Console.WriteLine(i + " ");
                }
            }
            Console.ReadLine();
        }

        static int Factorial(int n)
        {
            int i, fact = 1;
            for (i = 1; i <= n; i++)
            {
                fact = fact * i;
            }
            return fact;
        }
    }
}

Output:

Hello Codeauri Family,enter the starting number of the range here:
1
Similarly, enter the ending number of the range:
50
Okay, the Strong Numbers in the given range are:
1
2

Pro-Tips💡

Here are the step by step execution of above program:

using System; – This line is a using directive, which tells the compiler to use the System namespace, which includes classes and methods used in the program.

namespace Strong_Numbers – The namespace declaration creates a namespace named Strong_Numbers to group classes and other code elements in a logical and organized manner.

class Program – This is a class declaration, creating a class named Program.

static void Main(string[] args) – This is the main method of the program, the entry point for the program. When the program is executed, the code inside the Main method is executed first.

int start, end, i, j, temp, rem, sum; – This line declares seven integer variables: start, end, i, j, temp, rem, and sum.

Console.WriteLine("Enter the starting number of the range: "); – This line writes a message to the console asking the user to enter the starting number of the range.

start = Convert.ToInt32(Console.ReadLine()); – This line reads the starting number entered by the user, converts it to an integer using the Convert.ToInt32 method, and assigns it to the start variable.

Console.WriteLine("Enter the ending number of the range: "); – This line writes a message to the console asking the user to enter the ending number of the range.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

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

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X