Monday, April 22, 2019

Sum of cube of Digits

  • Problem Description

    Ganesh played game with his friend sanjay to find Sum of Cube of digits of the number he said. Help to Ganesh and sanjay to solve it by your code using union.

    Input Method

    Integer ranges from 1 to 999

    Output Method
    Sum of Cube of digits of the number
  • Test Case 1

    Input (stdin)
    123

    Expected Output
    Sum=6

    Cube=216
  • Test Case 2

    Input (stdin)
    998

    Expected Output
    Sum=26

    Cube=17576
  • Program
  • #include<stdio.h>
    struct cub
    {
    int a;
    }c;
    int main()
    {
    int sum=0,digit=0;
    scanf("%d",&c.a);
    while(c.a>0)
    {
    digit=c.a%10;
    sum=sum+digit;
    c.a=c.a/10;
    }
    printf("Sum=%d\n",sum);
    printf("Cube=%d",sum*sum*sum);
    return 0;
    }

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...