Answers for "what is armstrong number in c"

0

c program to check the number is armstrong or not

#include <stdio.h>
#include <math.h>
void main ()
{
    int n,t,r,c,s=0;
    printf("Enter the number: ");
    scanf("%d",&n);
    t=n;

        while(t!=0)
        {
            r=t%10;
            c=pow(r,3);
            s=s+c;
            t=t/10;
        }

        if(s==n)
            printf("Armstrong");
        else
            printf("Not Armstrong");
}
Posted by: Guest on June-24-2021
1

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.");
    }
}
Posted by: Guest on August-26-2020
0

armstrong number in c

//Bismillahir Rahmanir Rahim
#include <stdio.h>
#include <math.h>

int digit(int n, int count){
    while( n != 0){
        n/=10;
        count++;
    }
    return count;
}

int main(){
	    int n, rem, num, sum = 0, count = 0, digits;
	    while(1){
	        printf("Enter a number (type 0 to exit) : ");
            scanf("%d", &n);
            
            if(n==0){
                break;
            }
            digits = digit(n,count);
           
    		num=n;
    		while(num != 0){
    			rem = num % 10;
    			sum += pow(rem,digits);
    			num /= 10;
    		
    			}
    		
    		if(sum == n){
    			printf("%d is an armstrong number!\n", n);
    			sum = 0;
    		}else{
    			printf("%d is not an armstrong number!\n", n);
    			sum = 0;
    		}
	
	    }
	    
	return 0;
}
Posted by: Guest on August-13-2021
-1

Armstrong number

<form method="post">
        Enter the Number:
        <input type="number" name="number">
        <input type="submit" value="Submit">
    </form>
    <?php
    if ($_POST) {
        //get the number entered  
        $number = $_POST['number'];
        //store entered number in a variable  
        $a = $number;
        $sum  = 0;
        //run loop till the quotient is 0  
        while ($a != 0) {
            $rem   = $a % 10; //find reminder  
            $sum   = $sum + ($rem * $rem * $rem) || $sum = $rem; //cube the reminder and add it to the sum variable till the loop ends  
            $a   = $a / 10; //find quotient. if 0 then loop again  
        }
        //if the entered number and $sum value matches then it is an armstrong number  
        if ($number == $sum) {
            echo "Yes $number an Armstrong Number";
        } else {
            echo "$number is not an Armstrong Number";
        }
    }
//here is another example using while loop

$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";}
Posted by: Guest on August-05-2020

Code answers related to "what is armstrong number in c"

Browse Popular Code Answers by Language