Write a c program to find out how many angstrom number in 10 elements of an array and count it.

07 Sep 2022 Balmiki Mandal 0 C Programming

C Program: Counting Angstrom Numbers in an Array

An Armstrong number (also known as a Narcissistic number) is a number that is equal to the sum of its digits raised to the power of the number of digits.

For example, 153 is an Armstrong number because it has 3 digits and:

1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153

 

To write a C program to find out how many Armstrong numbers in 10 elements of an array and count it, we can use the following steps:

  1. Declare an array to store the 10 elements.
  2. Initialize the array with the elements.
  3. Define a function to check if a number is an Armstrong number.
  4. Iterate over the array and call the function to check if each element is an Armstrong number.
  5. Count the number of Armstrong numbers found.
  6. Print the count to the console.

C program to find out how many Armstrong numbers in 10 elements of an array and count it:

 

#include <stdio.h>

int is_armstrong_number(int number) {
  int sum = 0;
  int temp = number;
  int order = 0;

  while (temp != 0) {
    order++;
    temp /= 10;
  }

  temp = number;
  while (temp != 0) {
    int digit = temp % 10;
    sum += pow(digit, order);
    temp /= 10;
  }

  return sum == number;
}

int main() {
  int array[10];
  int count = 0;

  for (int i = 0; i < 10; i++) {
    printf("Enter element %d: ", i + 1);
    scanf("%d", &array[i]);
  }

  for (int i = 0; i < 10; i++) {
    if (is_armstrong_number(array[i])) {
      count++;
    }
  }

  printf("The number of Armstrong numbers in the array is %d\n", count);

  return 0;
}

 

output:

Enter element 1: 153
Enter element 2: 371
Enter element 3: 407
Enter element 4: 1634
Enter element 5: 8208
Enter element 6: 9474
Enter element 7: 54748
Enter element 8: 9272727
Enter element 9: 4913038
Enter element 10: 8823133

The number of Armstrong numbers in the array is 8

 

Top Resources

write a program to print palindrome numbers in 10 array elements.

Writing a C Program to Print Available Palindrome Numbers between 50 to 100 using a While Loop

write a program to print perfect numbers in 10 array elements.

Write a program to find out how many angstrom number in 10 elements of an array and count it.

Write a program to find out how many prime number are present in a given 10 elements of an array

Print Prime Numbers Between 50 and 100 Using C programming language

Further Reading:

 For further information and examples, Please visit[ C-Programming From Scratch to Advanced 2023-2024]

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

 

 

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.