Skip to main content

C code for checking a number if it's a Armstrong number or not

 Important Coding Questions (With C Language + Code Snippet)

Source: Click This Link


Definition of Armstrong Number: 

What is an Armstrong Number? A number is thought of as an Armstrong number if the sum of its own digits raised to the power number of digits gives the number itself. 
For example, 153, 370, 371, 407 are three-digit Armstrong numbers 
and, 1634, 8208, 9474 are four-digit Armstrong numbers and there are many more.

Input: 1634
Output: 1634 is an Armstrong number.

Input: 152
Output: 152 is not an Armstrong number.

Code Snippet:


#include<stdio.h>
int main() {
    int num, originalNum, remainder, result = 0;
    printf("Enter a three-digit integer: ");
    scanf("%d", &num);
    originalNum = num;
    while (originalNum != 0) {
        remainder = originalNum % 10;
        result += remainder*remainder*remainder;
        originalNum /= 10;
    }
    if (result == num)
        printf("%d is an Armstrong number.", num);
    else
        printf("%d is not an Armstrong number.", num);
    return 0;
}

Comments

Popular posts from this blog

What is the Difference Between Web Development and Android Development?

 What is the Difference Between Web Development and Android Development? While many people believe that web development and Android development are the same thing, this couldn’t be further from the truth. While both fields involve code and computers, the two actually have significantly different processes, tools, and skillsets required to complete their work. In this article, we’ll explore some of the key differences between web development and Android development in order to help you decide which profession may be better suited to your skill level and interests. Web Development vs Android Development The Ultimate Android vs Web Developers Showdown : There’s a massive amount of discussion around which type of development, web or android, is better. Both sides have passionate proponents who make compelling arguments. We don’t want to get into that argument. Instead, we’re going to look at both types of development and point out some strengths and weaknesses that make each different ...

Frequency Of Elements in an Array

  Algorithm Step 1: Create a map of integer to store key-value pairs. map<int,int> Step 2: Now iterate over all the elements of the array and count their frequency by the help of map Step 3: Now make a iterator for map to iterate over the map items Step 4: This is the final step. Just print all the elements and their frequency stored in map respectively  Code

C code to calculate product of even digits of a given number

 C code to calculate product of even digits of a given number Code Steps: 1. First input the number 2. Now initialize a variable =1, that stores the multiplication  3. Now start a while loop until number = 0 4. Inside while loop just find out all the digits by finding the remainder & check it if it is divisible by 2  5. If the number is divisible by 2 then multiply that number with the variable that was initialize = 1 6. At last return the multiplication storing variable.  C Code Snippet #include <stdio.h> int main (){     int num ;     int product = 1 ;     printf ( "Enter the number: " );     scanf ( " %d " , & num );     int temp = num ;     while ( num != 0 ){                 int digit = num % 10 ;         num = num / 10 ;         if ( digit % 2 == 0 ){         ...