Saturday, 21 November 2020

Write a program in C++ to Create a Single Dimensional Array of n integers. Print only the Armstrong numbers from the Array.

 #include<iostream>

using namespace std;

int main()

    {

        int n,n1,d,cube,sum,i;

        cout<<"Enter the size of the array\n";

        cin>>n;

        int a[n];

        cout<<"Enter "<<n<<" Numbers\n";

        for(i=0;i<n;i++)

        cin>>a[i];

        for(i=0;i<n;i++)

        {

         n1=a[i];

         sum=0;

         while(a[i]>0)

        {

          d=a[i]%10;

          cube=d*d*d;

          sum=sum+cube;

          a[i]=a[i]/10;

        }

        if(sum==n1)

        cout<<n1<<" is an Armstrong Number\n";

        else

        cout<<n1<<" is not an Armstrong Number\n";

        }

    }

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...