Skip to main content

C Program to Check whether a given Number is Armstrong

C Program to Check whether a given Number is Armstrong


/*
 * C Program to Check whether a given Number is Armstrong
 */
#include <stdio.h>
#include <math.h>
 
void main()
{
    int number, sum = 0, rem = 0, cube = 0, temp;
 
    printf ("enter a number : ");
    scanf("%d", &number);
    temp = number;
    while (number != 0)
    {
        rem = number % 10;
        cube = pow(rem, 3);
        sum = sum + cube;
        number = number / 10;
    }
    if (sum == temp)
        printf ("The given no is armstrong no");
    else
        printf ("The given no is not a armstrong no");
}

Output :

enter a number : 370
The given no is armstrong no

enter a number : 1500
The given no is not a armstrong no

Comments

Popular posts from this blog

KALI LINUX COMMANDS

KALI LINUX COMMANDS A-Z of Kali Linux commands are here below: a apropos  Search Help manual pages (man -k) apt-get  Search for and install software packages (Debian) aptitude  Search for and install software packages (Debian) aspell  Spell Checker awk  Find and Replace text, database sort/validate/index b basename  Strip directory and suffix from filenames bash  GNU Bourne-Again SHell bc  Arbitrary precision calculator language bg  Send to background break  Exit from a loop builtin  Run a shell builtin bzip2  Compress or decompress named file(s) c cal  Display a calendar case  Conditionally perform a command cat  Concatenate and print (display) the content of files cd  Change Directory cfdisk  Partition table manipulator for Linux chgrp  Change group ownership chmod  Change access permissions chown  Change file owner and group chroot  Run a command ...

Graphics in C: Using Colors in Text Mode

Graphics in C/C++: Using Colors in Text Mode In Advance Learning Tutorial, today we will learn about the colors in C / C + +. So far, you have used only two colors in your program Black and White, Black color in Background and White color foreground, i.e. to print the character. By default, all compilers use these two colors. But if you want to print any character on your screen from the color of your choice, then you can do it with the help of the functions described below. Keep in mind that the functions described below will only run on Text Mode. Using the colors, you can make your program more attractive in C /C++. Total 15 colors have been defined in C++. To use any color, you can use the name of that color or the corresponding value of that color. This value is already defined in the compiler. All the 15 colors and their values are given in the table below. Values of Colors 1. BLACK 0 2. BLUE 1 3. GREEN 2 4. CYAN 3 5. RED 4 6...

C Reverse a Sentence Using Recursion

C Reverse a Sentence Using Recursion Examples #include void reverseSentence(); int main() { printf("Enter a sentence: "); reverseSentence(); return 0; } void reverseSentence() { char c; scanf("%c", &c); if( c != '\n') { reverseSentence(); printf("%c",c); } } Output Enter a sentence: margorp emosewa awesome program