Users Online

· Guests Online: 61

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Print Armstrong Number between 1 to 1000

C# Program to Print Armstrong Number between 1 to 1000

 

This is a C# Program to print all the armstrong numbers from 1 to 1000.

Problem Description

This C# Program Prints all the Armstrong Numbers from 1 to 1000.

Problem Solution

Here an Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.

Program/Source Code

Here is source code of the C# Program to Print all the Armstrong Numbers from 1 to 1000. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 *  C# Program to Print all the Armstrong Numbers from 1 to 1000
 */
using System;
class Program
{
    static void Main()
    {
        int a, b, c, d;
        for (int i = 1; i <= 1000; i++)
        {
            a = i / 100;
            b = (i - a * 100) / 10;
            c = (i - a * 100 - b * 10);
            d = a * a * a + b * b * b + c * c * c;
            if (i == d)
            {
                System.Console.WriteLine("{0}", i);
            }
        } 
        Console.Read();
    }
}
Program Explanation

In this C# program, Using for loop compute the Armstrong numbers. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. Compute the division of the value of ‘i’ variable by 100.

Multiply the value of ‘a’ variable by 100 and compute the difference of the resulted value with the value of ‘i’ variable and divide the resulted value by 10. Compute the sum of the cube of ‘a’, ‘b’ and ‘c’ variables.

If condition statement is used to check the value of ‘i’ variable is equal to‘d’, if the condition is true then execute the statement and print the Armstrong numbers.

Runtime Test Cases
 
1
153
370
371
407
1000

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.04 seconds
10,854,991 unique visits