TCS Coding Problem 7

15 comments on “TCS Coding Problem 7”


  • RAKESH

    //java
    import java.util.Scanner;

    public class ArmstrongNumber {

    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    String s=String.valueOf(n);
    int x=0;

    for(int i=0;i<s.length();i++)
    {
    x=x+(int) Math.pow(Integer.valueOf(String.valueOf(s.charAt(i))),s.length() );
    }
    if(x==n)
    {
    System.out.print(n+" is Armstrong Number");
    }
    else
    {
    System.out.print(n+" is not Armstrong Number");
    }
    }

    }


  • dee.pansh18johri

    #include
    using namespace std;
    int main() {
    // your code goes here
    int n;
    cin>>n;
    int len=0;
    int m=n;
    while(m)
    {
    len++;
    m/=10;
    }
    double sum=0;int w=n;
    while(n)
    {
    sum+=pow(n%10,len);
    n/=10;
    }
    if(sum==w)
    cout<<"ARMSTRONG";
    else
    cout<<"NOT AN ARMSTRONG NUMBER";
    return 0;
    }
    // O(N)