Skip to main content

C program to check whether a number is Armstrong or not



Code 1:
1. Warp to check a number is Armstrong
2. C program to check whether a number is Armstrong or not
3. Simple c program for Armstrong number
4. Armstrong number in c with output

#include<stdio.h>
int main(){
    int num,r,sum=0,temp;

    printf("Enter a number: ");
    scanf("%d",&num);

    temp=num;
    while(num!=0){
         r=num%10;
         num=num/10;
         sum=sum+(r*r*r);
    }
    if(sum==temp)
         printf("%d is an Armstrong number",temp);
    else
         printf("%d is not an Armstrong number",temp);

    return 0;
}

Sample output:
Enter a number: 153
153 is an Armstrong number

The time complexity of a program that determines Armstrong number is: O (Number of digits)

Code 2:
1. Write a c program for Armstrong number
2. C program for Armstrong number generation
3. How to find Armstrong number in c
4. Code for Armstrong number in c

#include<stdio.h>
int main(){
    int num,r,sum,temp;
    int min,max;

    printf("Enter the minimum range: ");
    scanf("%d",&min);

    printf("Enter the maximum range: ");
    scanf("%d",&max);

    printf("Armstrong numbers in given range are: ");
    for(num=min;num<=max;num++){
         temp=num;
         sum = 0;

         while(temp!=0){
             r=temp%10;
             temp=temp/10;
             sum=sum+(r*r*r);
         }
         if(sum==num)
             printf("%d ",num);
    }

    return 0;
}

Sample output:
Enter the minimum range: 1
Enter the maximum range: 200
Armstrong numbers in given range are: 1 153

Code 3:
1. Armstrong number in c using for loop

#include<stdio.h>
int main(){
    int num,r,sum=0,temp;

    printf("Enter a number: ");
    scanf("%d",&num);

    for(temp=num;num!=0;num=num/10){
         r=num%10;
         sum=sum+(r*r*r);
    }
    if(sum==temp)
         printf("%d is an Armstrong number",temp);
    else
         printf("%d is not an Armstrong number",temp);

    return 0;
}

Sample output:
Enter a number: 370
370 is an Armstrong number
Logic of Armstrong number in c

Code 4:
1. C program to print Armstrong numbers from 1 to 500
2. C program for finding Armstrong numbers

#include<stdio.h>
int main(){
    int num,r,sum,temp;

    for(num=1;num<=500;num++){
         temp=num;
         sum = 0;

         while(temp!=0){
             r=temp%10;
             temp=temp/10;
             sum=sum+(r*r*r);
         }
         if(sum==num)
             printf("%d ",num);
    }

    return 0;
}

Comments

Popular posts from this blog

Types of Yarn twist | different types of yarn twist | S twist | Z twist

Types of Yarn twist different types of yarn twist S twist Z twist“S” TWIST: A single yarn has “S” twist if when it is held in the vertical direction , the fibers inclined to the conform in direction of slope of the contact portion of the letter “S”. axis of the yarn “Z” TWIST. A single has “Z” twist if when it is held in the vertical direction, the fibers inclined to the yarn axis conform in the direction of the slope to the central portion of the letter “Z”. DIRECTION OF TWIST: In the designation of yarns, it is essential to specify the direction of twist. Besides its importance in simplifying the trade, it is of great technical importance in designing fabrics. For example, in a twill fabric, the direction of twist in the yarn is of particular importance in determining the predominance of twill effect. For a   right-handed twill, the best contrasting effect will be obtained when a yarn with Z twist is used; on the other-hand a left-handed twist will produce a fabric ha...

macro-structure of cotton fiber | Under a microscope cotton

Under a microscope a cotton fiber appears as a very fine, regular fiber, looking like a twisted ribbon or a collapsed and twisted tube. These twists are called convolutions there are about sixty convolutions per centimeter. The convolutions give cotton an uneven fiber surface, which increases inter-fiber friction and enables fine cotton, yearns of squatted strength to be spun. The appearance of the cotton fiber’s cross sections is referred as being kidney-shaped. The micro structure of cotton The cotton fiber is a single plant cell. Its cross-section is oval, compared with the normal hexagonal plant cell. Cotton has a district cuticle, well developed primary and secondary walls and a lumen. Layer 1 the cuticle is a waxy protective layer that provides water resistance to the fibers as they are growing. This lawyer is removed by scouring during processing before spinning.

Definition of yarn | different types of yarn | class of yarn

A.         CABLED YARN :- These type of yarn are made by twisting together two or more multi folded plied yarns. In general, it is constructed by twisting the plied yarns around each other successively in the opposite direction the preceding twist, i.e. S/Z/S or Z/S/Z. As a result, the opposite twist direction cause the plies to grip each other and maintain adherence. These yarns are hard, rough and strong Example CORDS.   B.         SINGLE YARN :- It is the simplest continuous strand of textile material composed of the following:- i)                     Continuous Filament:- These type of yarn are simplest in structures but they can be subjected to different modifying processes to change their extensibility and other properties. They are of the following types: 1) Mono filament which contains only ONE filamen...