Code.GeekInterview.com
  I am new, Sign me up!
 
Code Samples C
 

Check if the input number is a Amstrong number or not


Code ResourceAuthor: Jimmy Zorald  

Difficulty Level:

Published: 25th May 2007   Read: 3124 times  

Filed in: C
Add Comment


 


This is a very simple code that checks if a number is a Amstrong number or not. This is mostly useful for beginners who are starting to learn C programming.

 


Sample Code
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <math.h>
  6.  
  7. void main()
  8. {
  9.         long num1,num2=0,mcount=0, nums;
  10.         char str1[35], strc;
  11.  
  12.         clrscr();
  13.         printf("Enter a number : ");
  14.         scanf("%ld",&num1);
  15.  
  16.          ltoa(num1,str1,10);
  17.          while (mcount <= (strlen(str1)-1))
  18.          {
  19.           strc = str1[mcount];
  20.           nums = atoi(&strc);
  21.           num2 = num2+pow(nums,3);
  22.           mcount = mcount+1;
  23.          }
  24.  
  25.          if (num1 == num2)
  26.          {
  27.           printf("Amstrong Number : %ld",num2);
  28.          }
  29.          else
  30.          {
  31.           printf("Not a Amstrong Number.");
  32.          }
  33.    getch();
  34. }
  35.  
Copyright GeekInterview.com


Next Article: Glittering Eyes - Animation Effect


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Comment


Members Please Login

Name:  Email: (Optional. Used for Notification)

Title:
 
Comment:
Validation Code: <=>  (Enter this code in text box)





Popular Coders

# Coder NameHits
1. kaivalya198917481
2. chandrikakr5349
3. meefriend4ever4316
4. deepu084085
5. sripri3350
6. Jimmy Zorald3125
7. Rajani1951
8. norman1669
9. reliable1573
10. shiva074519

Active Coders

# Coder NameCodes
1. kaivalya19894
2. sripri1
3. Jimmy Zorald1
4. norman1
5. Rajani1
6. meefriend4ever1
7. chandrikakr1
8. reliable1
9. deepu081
10. shiva0741

Refined Tags

 

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape