Close Menu
  • Home
  • AI News
  • AI Startups
  • Deep Learning
  • Interviews
  • Machine-Learning
  • Robotics

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot

Siemens Introduces AI Brokers for Industrial Automation

May 12, 2025

AI That Can’t Be Trusted Can’t Be Scaled—And AI That Can’t Be Scaled Is Simply Theater

May 12, 2025

Cache-Enhanced Retrieval-Augmented Era (RAG)

May 12, 2025
Facebook X (Twitter) Instagram
The AI Today
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn TikTok
SUBSCRIBE
  • Home
  • AI News
  • AI Startups
  • Deep Learning
  • Interviews
  • Machine-Learning
  • Robotics
The AI Today
Home»Deep Learning»Armstrong Quantity in C : Examples and Packages
Deep Learning

Armstrong Quantity in C : Examples and Packages

By April 26, 2024Updated:May 5, 2024No Comments6 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Reddit WhatsApp Email
Armstrong Quantity in C : Examples and Packages
Share
Facebook Twitter LinkedIn Pinterest WhatsApp Email


What’s Armstrong Quantity in C?

An Armstrong quantity (also referred to as a narcissistic quantity, plenary quantity, or pluperfect quantity) is a quantity that is the same as the sum of its personal digits every raised to the ability of the variety of digits. For instance, 153 is an Armstrong quantity as a result of:

It’s named after Michael F. Armstrong, who used it for example in a programming downside in 1969. These numbers are intriguing in arithmetic and programming as a result of they’re comparatively uncommon and sometimes utilized in workouts to check programming expertise.

Armstrong Quantity Instance

If the Armstrong quantity is a constructive integer of order n then it may be outlined as,

abcde…. = pow (a, n) + pow (b, n) + pow (c, n) + pow (d, n) + pow (e, n) + ………

For instance : 0, 1, 153, 370, 371, 1634 and so on.

Let’s verify whether or not 370 is an Armstrong quantity or not

370 = (3 * 3 * 3) + (7 * 7 * 7) + (0 * 0 * 0)

Right here,    

(3 * 3 * 3) = 27

(7 * 7 * 7) = 343

(0 * 0 * 0) = 0

27 + 343 + 0 = 370, which is the same as the given quantity; therefore it's an Armstrong quantity.

Let’s verify 4 digits Armstrong quantity:

1634 = (1 * 1 * 1 * 1) + (6 * 6 * 6 * 6) + (3 * 3 * 3 * 3) + (4 * 4 * 4 * 4)

Right here, 

(1 * 1 * 1 * 1) = 1

(6 * 6* 6 * 6) = 1296

(3 * 3 * 3 * 3) = 81

(4 * 4 * 4 * 4) = 256

1 + 1296 + 81 + 256 = 1634, which is the same as the given quantity; therefore it's an Armstrong quantity.

Algorithm of Armstrong Quantity in C

  1. Take enter from the consumer
  2. Initialize sum = 0 and take momentary variable to briefly retailer consumer enter (var = num)
  3. Now discover out the whole variety of digits within the given quantity
  4. Complete variety of digits get saved in a
  5. Repeat the loop until var > 0
  6. Retailer the output of whereas loop in sum
  7. Test whether or not the consumer quantity is the same as sum or not
  8. Whether it is equal than print “It’s an Armstrong quantity”
  9. Else print “It’s not an Armstrong quantity”

Program of Armstrong Quantity in C

#embody <stdio.h>
#embody <conio.h>
 
int primary ()
{
int num, var, rem, sum = 0, a = 0 ;
 
printf ( “ Please enter an integer: “ );  // Taking the consumer enter
scanf ( “%d”, &num );
 
var = num;
 
whereas (var != 0)	// Discovering the numbers of digits in a given quantity
{
var = var / 10;
++a;
}
 
var = num;
 
whereas (var > 0 )  	// Calculate the quantity to verify  it's Armstrong or not
{
rem = var % 10;
sum = sum +  pow( rem, a );
var = var / 10;
}
 
if ( sum == num )	// Test whether or not the sum is the same as the given variety of not
{
printf ( “ %d is an Armstrong quantity n ”, num );
}
else
{
printf ( “ %d shouldn't be an Armstrong quantity n ”, num );
}
return 0;
}

Output 1:

Please enter an integer: 371

371 is an Armstrong quantity

Output 2:

Please enter an integer: 1045

1045 is an Armstrong quantity

Rationalization

Within the above code, we have now first declared all of the variables which are wanted in this system. The num is said to carry the consumer enter. The var is used for the momentary storage, after which rem is used to carry the rest that’s required for calculation. Ultimately, we have now the sum and a, that are assigned to zero.

We’re accepting consumer enter after which assigning that quantity to num. Then we assign this quantity to var in order that we are able to make our calculation and maintain the consumer enter protected within the num variable. 

Now we’re calculating the variety of digits that consumer enter has. For that, we have now assigned num worth to var, and we have now taken some time loop. The whereas loop will probably be working till (var !=0) after which divide var by ten in order that we are able to rely the whole variety of digits in that quantity. Since var is of integer kind, it won’t retailer a decimal quantity, after which every time, the worth of an will increase by 1. This course of is repeated till var is the same as zero. After that, it exits the loop.

Now once more, we assign num worth to var. Then we begin the loop, and this loop will run until var is bigger than zero. We’ve three steps to carry out contained in the loop. First, we discover the rest of the quantity, after which we calculate the ability of the rest utilizing pow(rem, a), the place rem represents the rest, and a represents the ability, i.e., complete variety of digits in a quantity, which was calculated above. Now we divide the var by 10, and that is completed as a result of we don’t require the final digit of the quantity as a result of we have now already used it. Since var is an integer kind, it neglects the decimal worth and shops the integer worth. This course of is repeated until var is bigger than zero; after that, it exits from the loop, and the ultimate worth is saved in sum.

As soon as the management strikes out of the loop, the if assertion checks whether or not sum is the same as the num or not, the place the num is the enter given by the consumer. If the sum is the same as num, then it’s an Armstrong quantity. Else it’s not an Armstrong quantity.

So, right here is all about “Armstrong Quantity in C.” We hope you discover this implementation informative. Keep tuned for extra upcoming blogs. Take up the Free On-line C Programming for Rookies Course and be taught extra such ideas!

Related Posts

Microsoft Researchers Introduces BioEmu-1: A Deep Studying Mannequin that may Generate Hundreds of Protein Buildings Per Hour on a Single GPU

February 24, 2025

What’s Deep Studying? – MarkTechPost

January 15, 2025

Researchers from NVIDIA, CMU and the College of Washington Launched ‘FlashInfer’: A Kernel Library that Offers State-of-the-Artwork Kernel Implementations for LLM Inference and Serving

January 5, 2025
Misa
Trending
Machine-Learning

Siemens Introduces AI Brokers for Industrial Automation

By Editorial TeamMay 12, 20250

Automating automation: AI brokers enhancing Siemens Industrial Copilots Future imaginative and prescient: ecosystem of Industrial…

AI That Can’t Be Trusted Can’t Be Scaled—And AI That Can’t Be Scaled Is Simply Theater

May 12, 2025

Cache-Enhanced Retrieval-Augmented Era (RAG)

May 12, 2025

Learn how to Construct AI Brokers Utilizing Trendy Agent Frameworks

May 9, 2025
Stay In Touch
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
  • Vimeo
Our Picks

Siemens Introduces AI Brokers for Industrial Automation

May 12, 2025

AI That Can’t Be Trusted Can’t Be Scaled—And AI That Can’t Be Scaled Is Simply Theater

May 12, 2025

Cache-Enhanced Retrieval-Augmented Era (RAG)

May 12, 2025

Learn how to Construct AI Brokers Utilizing Trendy Agent Frameworks

May 9, 2025

Subscribe to Updates

Get the latest creative news from SmartMag about art & design.

The Ai Today™ Magazine is the first in the middle east that gives the latest developments and innovations in the field of AI. We provide in-depth articles and analysis on the latest research and technologies in AI, as well as interviews with experts and thought leaders in the field. In addition, The Ai Today™ Magazine provides a platform for researchers and practitioners to share their work and ideas with a wider audience, help readers stay informed and engaged with the latest developments in the field, and provide valuable insights and perspectives on the future of AI.

Our Picks

Siemens Introduces AI Brokers for Industrial Automation

May 12, 2025

AI That Can’t Be Trusted Can’t Be Scaled—And AI That Can’t Be Scaled Is Simply Theater

May 12, 2025

Cache-Enhanced Retrieval-Augmented Era (RAG)

May 12, 2025
Trending

Learn how to Construct AI Brokers Utilizing Trendy Agent Frameworks

May 9, 2025

Rafay Launches Serverless Inference Providing to Speed up Enterprise AI Adoption and Enhance Revenues for GPU Cloud Suppliers

May 9, 2025

DataRobot Launches New Federal AI Software Suite to Unlock Effectivity and Impression

May 9, 2025
Facebook X (Twitter) Instagram YouTube LinkedIn TikTok
  • About Us
  • Advertising Solutions
  • Privacy Policy
  • Terms
  • Podcast
Copyright © The Ai Today™ , All right reserved.

Type above and press Enter to search. Press Esc to cancel.