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 numberTest Case 1
Input (stdin)123
Expected OutputSum=6 Cube=216
Test Case 2
Input (stdin)998
Expected OutputSum=26 Cube=17576Program
#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
Note: only a member of this blog may post a comment.