Total members 11791 |It is currently Mon Aug 19, 2019 9:23 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





i an trying to solve a problem that has a no. "abc", if we make the cubic power for each digit of the number, then add the results, it should give the same number "abc" as above
im using the C language and need some help to execute my program
here are the codes i used :

Code:
include<stdio.h>

int main ()
{
   int   pow (int x, int y);
   
   int i,j,k;
   int sum=0;
   int c,d,f;

   for(i=1;i<5;i++)
   {for(j=1;j<5;j++)
   {for(k=1;k<5;k++)
   {
   
   c==i^3;
   d==j^3;
   f==k^3;
   }}}
      
   sum=sum+c+d+f;

   if(sum=i*100+j*10+k)
   
   {printf("the %d %d %d are numbers having the sum of cubic power of each is %d\n\n\n",i,j,k,sum);
   
   }
   return 0;
   }


mail : [email protected]




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

I really don't understand your problem .But it is seems interesting can you clear it more .


Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time

what compiler you are using in order to understand and help you to execute your programme each one has its own execution methods in some you might need to add some specified libraries;)


Author:
Moderator
User avatar Posts: 47
Have thanks: 1 time

Hi cutedevils,

quite late, but here it is.

To face the picture: You want to know, which three-digit-number is equal to the sum of the cubic-power of its digits. so abc = a^3 + b^3 + c^3.

A few words to C/C++.

  • Neither C nor C++ are having a power operator ^ like Basic. But the operator ^ does exist. It is the XOR operator.
  • The line c == i^3 is syntactically correct but does nothing. Its meaning is: compare c to (i XOR 3). But the result of this comparison is discarded because it isn't assigned to any variable.
  • Your summing code is at the wrong position. It is executet after all loops. It will only be executed for the i = 4, j = 4 and k = 4.
  • The comparison if(sum=i*100+j*10+k) will always evaluate to true. Because the comparison is done with "==". The meaning of your line is: assign (i*100+j*10+k) to s and test if s is unequal to zero. Yes, the if statement is quite confusing in C/C++.

A corrected version looks like this:

Code:
#include <stdio.h>

int main()
{
   int i, j, k;
   int c, d, e;
   int sum = 0;
   
   for (i = 1; i < 10; i++) {
      for (j = 1; j < 10; j++) {
         for (k = 1; k < 10; k++) {
            c = i*i*i;
            d = j*j*j;
            e = k*k*k;
            sum = c + d + e;
            if (sum == (i*100 + j*10 + k)) {
               printf("%d%d%d = %d^3 + %d^3 + %d^3 = %d + %d + %d\n", i,j,k,i,j,k,c,d,e);
            }
         }
      }
   }
   return 0;
}


The following output will be done:

Code:
153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27
371 = 3^3 + 7^3 + 1^3 = 27 + 343 + 1


Best regards


Author:
Newbie
User avatar Posts: 4
Have thanks: 1 time

For this message the author apeter has received gratitude : msi_333

Did you fix the issues?


Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 5 posts ] 

  Related Posts  to : cubic power for each digit
 All 4 CCNA semesters in power point pass?     -  
 Power builder with DB2 - Virginia Garden, FL- Contract     -  



Topic Tags

C++ Math






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com