TCS Coding Problem 7

10 comments on “TCS Coding Problem 7”


  • Pogakula

    #python3
    def armstrong(s):
    return sum([int(i)**len(str(s)) for i in str(s)])==s
    num=int(input(‘enter the number:\t’))
    print(armstrong(num))


  • swapnil

    num = int(input())
    numvalue=num
    arr = []
    while num > 0:
    l = num % 10
    num = num – l
    arr.append(l)
    num = num // 10
    res = 0
    for i in arr:
    p = 1
    for j in range(len(arr)):
    p = p * i
    res+=p
    if(res==numvalue):
    print(“Yes”)
    else:
    print(“no”)


  • swapnil

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner s=new Scanner(System.in);
    String s1=s.nextLine();
    String[] s2=s1.split(“”);
    int j=0;
    int[] arr=new int[s2.length];
    for(String i:s2) {

    arr[j]=Integer.parseInt(i);
    j+=1;
    }
    int sum=0;
    int prod=1;
    for(int i:arr) {
    prod=1;

    for(int k =0;k<arr.length;k++) {
    prod=prod*i;

    }

    sum=sum+prod;

    }

    if(sum==Integer.parseInt(s1)) {
    System.out.println("YES");

    }else {
    System.out.println("NO");
    }
    }


  • swapnil

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner s=new Scanner(System.in);
    String s1=s.nextLine();
    String[] s2=s1.split(“”);
    int j=0;
    int[] arr=new int[s2.length];
    for(String i:s2) {

    arr[j]=Integer.parseInt(i);
    j+=1;
    }
    int sum=0;
    for(int i:arr) {

    sum=sum+(i*i*i);

    }

    if(sum==Integer.parseInt(s1)) {
    System.out.println(“YES”);

    }else {
    System.out.println(“NO”);
    }
    }


  • The Bong

    public class ArmstrongNumber {
    public static void main(String[] args) {
    System.out.println(checkArmstrong(153));
    System.out.println(checkArmstrong(1253));
    }
    static boolean checkArmstrong(int number) {
    int temp = number;boolean isArmstrong = false;
    int sum = 0;
    while (temp > 0) {
    int remainder = temp % 10;
    sum += (int)Math.pow(remainder, Integer.toString(number).length());
    temp /= 10;
    }
    if(sum == number) {
    isArmstrong = true;
    }
    return isArmstrong;
    }
    }


  • The Bong

    public class ArmstrongNumber {
    public static void main(String[] args) {
    System.out.println(checkArmstrong(153));
    System.out.println(checkArmstrong(1253));
    }
    static boolean checkArmstrong(int number) {
    int temp = number;boolean isArmstrong = false;
    int sum = 0;
    while (temp > 0) {
    int remainder = temp % 10;
    sum += remainder*remainder*remainder;
    temp /= 10;
    }
    if(sum == number) {
    isArmstrong = true;
    }
    return isArmstrong;
    }
    }


  • kandukuri

    #include
    #include

    void armstrong(int a, int count)
    {
    int demo = a;
    int sum = 0, digit1;
    while (a > 0)
    {
    digit1 = a % 10;
    sum = sum + pow(digit1, count);
    a = a / 10;
    }
    if (sum == demo)
    {
    printf(“yes”);
    }
    else
    {
    printf(“no”);
    }
    }

    void main()
    {
    int num, digit, count = 0, n;
    printf(“please enter the num: “);
    scanf(“%d”, &num);
    int demonum = num;
    while (num > 0)
    {
    digit = num % 10;
    count++;
    num = num / 10;
    }
    armstrong(demonum, count);
    }


  • abhijeet singh

    ********************************very easy c++ program**************************
    #include
    #include
    using namespace std;
    int main()
    {
    int origNum, num, rem,count=0;
    cout <> origNum;
    num = origNum;
    while(num != 0)
    {
    rem = num % 10;
    num /= 10;
    count++;
    }
    num=origNum;
    rem=1;
    int sum=0;

    while(num!=0)
    {rem=num%10;
    sum=sum+pow(rem,count);
    num /= 10;
    }
    if(sum==origNum)
    {
    cout<<"armstrong no";

    }
    }


  • Meghana

    u gave in a different process.
    for armstrong there is a method to execute.please provide as easy as possible.it is a loss for the paid material members like me


    • Mohd Saif

      # python 🙂 Meghana

      n=int(input())
      y=len(str(n))
      temp==n
      x=0
      while(n>0):
      a=n%10
      x=x+pow(a,y)
      n=n//10
      if(temp==x):
      print(f”YES {temp} is a Armstrong Number”)
      else:
      print(f”NO {temp} is a Armstrong Number”)