Digital+G1+Intro+small

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

source-4280758_960_720

Dr. A.P.J. Abdul Kalam Technical University, Lucknow

KCS101 / KCS201 Programming for Problem Solving - Using C Language


Lab Exercises


19. Write a program to print Armstrong numbers from 1 to 1000.


/*
 File: Prgrm19.c
 Author: Aditya Saini
 Date: Sept 30, 2019
 Description: Program to print Armstrong numbers from 1 to 1000.
*/

#include <stdio.h>
#include <math.h>

int Armstrong (int);

int main (void)
{
               int number;

               //Finding the Armstrong numbers and output the result.
               printf ("Armstrong numbers from 1 to 1000:  ");
               for (number = 1; number <= 1000; number++)
               {
                              if (Armstrong (number))
                                             printf ("%d  ", number);
               }

               return 0;
};

int Armstrong (int number)
{
               int number_of_digits;
               int ArmStrong;
               int temp;

               //Finding number of digits;
               temp = number;
               number_of_digits = 0;
               while (temp != 0)
               {
                              temp = temp / 10;
                              number_of_digits++;
               }

               //Finding if the number is Armstrong or not
               ArmStrong = 0;
               temp = number;
               while (temp != 0)
               {
                              ArmStrong = ArmStrong + pow (temp % 10, number_of_digits);
                              temp = temp / 10;
               }

               if (number == ArmStrong)
                              return 1;
               else
                              return 0;
};

Output

Armstrong numbers from 1 to 1000:  1  2  3  4  5  6  7  8  9  10  153  370  371  407



11 comments:

  1. blogger_logo_round_35

    very nice put up, i definitely love this web site, carry on it visual identity

    ReplyDelete
  2. 7c07da47-165b-4aac-962d-88956d6ae6c5
  3. blogger_logo_round_35

    Thank you for having the time to discuss this topic. I truly appreciate it. I’ll stick a link of this entry in my site. brand

    ReplyDelete
  4. blogger_logo_round_35

    I have beeing scouring the google for this information and simply needed to thank you for the post. BTW, simply off topic, how can I get a duplicate of this theme? – Thanks ipad mockups

    ReplyDelete
    Replies
    1. 7c07da47-165b-4aac-962d-88956d6ae6c5

      Thank you James Jones for the appreciation. You can get this theme from
      https://pixel-template.blogspot.com/

      Delete
  5. malecostume-512

    I like this website very much so much fantastic information. macbook sketch

    ReplyDelete
  6. blogger_logo_round_35

    Hey there! Wonderful stuff, please do tell us when you post again something similar! android mockups

    ReplyDelete
    Replies
    1. 7c07da47-165b-4aac-962d-88956d6ae6c5

      Thank you sdexter. Soon you will see more posts.

      Delete
  7. blogger_logo_round_35

    According to my point of view , learning C programs is not easy , indeed , students have to face a lot of trouble in writing their language assignments but if you are worried you can select to Dissertation Writing Services

    ReplyDelete

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib