Armstrong Number coderinme

Armstrong Number coderinme

Armstrong Number coderinme
In order to check whether the entered number is an Armstrong number or not, we find the sum of cubes of each digit in the number. If the sum is same as the given number, then the number is an Armstrong number, otherwise it is not.
Let’s check out using C

#include
int main()
{
int a,b,c=0,x;
printf("Enter the Number: ");
scanf("%d",&a);
x = a;
while( a != 0 )
{
b = a % 10;
a = a / 10;
c = c + b * b * b;
}
printf("sum of each digit after cubing: %d\n",c);
if(c == x)
printf("%d is an Armstrong number",x);
else
printf("%d is not an Armstrong number",x);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.