what is armstrong number in c code example
Example 1: armstrong number
sum of cubes of the digits
Example 2: armstrong number in c
#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;
}
Example 3: armstrong number in c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int cube(int a)
{
int c;
c = a*a*a;
return c;
}
int armnum(int *a)
{
int x = *a, n = 0, rem, r = 0;
while (x != 0) {
x /= 10;
n++;
}
x = *a;
while (x != 0) {
rem = x % 10;
r += cube(rem);
x /= 10;
}
if(r == *a){
return 1;
}
}
int main()
{
int a, y;
scanf("%d", &a);
y = armnum(&a);
if(y == 1){
printf("It is an Armstrong number.");
}
else{
printf("It is not an Armstrong number.");
}
}
Example 4: Armstrong number
<form method="post">
Enter the Number:
<input type="number" name="number">
<input type="submit" value="Submit">
</form>
<?php
if ($_POST) {
$number = $_POST['number'];
$a = $number;
$sum = 0;
while ($a != 0) {
$rem = $a % 10;
$sum = $sum + ($rem * $rem * $rem) || $sum = $rem;
$a = $a / 10;
}
if ($number == $sum) {
echo "Yes $number an Armstrong Number";
} else {
echo "$number is not an Armstrong Number";
}
}
$num=300;
$total=0;
$x=$num;
while($x!=0){
$rem=$x%10;
$total=$total+($rem*$rem*$rem);
$x=$x/10;
}
if($num==$total){
echo "Yes it is an Armstrong number";}
else
{echo "No it is not an armstrong number";}