You are here:

C/Sum of Cubes of numbers

Advertisement


Question
Write a program that examines all the numbers from 1 to 999, displaying all those for which the sum of cubes of the digits equals the number itself. For example, 153, 371.

1^3+5^3+3^3=153
3^3+7^3+1^3=371 ans so on....

**************
Sir,
 I am not getting the solution of this question, please make the correction so that I get the answer. Given below the wrong solution :



#include<stdio.h>
main()
{
     int i,rem,z;
     long sum=0;
     printf("\nEnter the mximum number :");
     scanf("%d",&i);
     
        while(i>0)
        {
           rem=i%10;
           sum=sum*10+rem;
           i=i/10;
           z=sum*sum*sum;
           printf("Answer: %d",z);
        }
getch();
}

Answer
Hi dear Abhimanyu !

 Sorry for the delay , since i was busy with some project issues , kindly check out the following code!

#include<stdio.h>
void main()
{
  int i,n,temp,digit;
  long sum=0;
  printf("\nEnter the mximum number :");
  scanf("%d",&n);

  for( i = 0; i <=n ;i++)
  {
     digit =0;
     sum=0;
     temp = i;
     while(temp >0)
     {
        digit = temp%10;
        sum+=digit * digit *digit;
        temp = temp/10;
     }
     if( sum == i)
     {
        printf("%d\n" , sum);
     }
  }
  getch();
}

Note: I didn't test this code , kindly revert me in case of issues !

Thanks and Regards!
Prince M. Premnath

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.