Author Topic: problem with compiler or my code ???  (Read 3043 times)

mrrc.suresh

  • Guest
problem with compiler or my code ???
« on: November 28, 2017, 12:42:23 pm »
help required,

i am using Code::Blocks 13.12 in windows 10


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
   int originalnum,digit,tempNum;
   int result=0,power=0;
   cout<<"Enter A Number: ";
   cin>>originalnum;
   tempNum=originalnum;
   while(tempNum!=0)
   {
      tempNum=tempNum/10;
      power++;
   }
   tempNum=originalnum;
   while(tempNum!=0)
   {
      digit=tempNum%10;
      result=result+pow(digit,power);
      tempNum=tempNum/10;
   }

   cout<<result;

      return 0;
}


for this code iam not getting the result for input 153 is coming 152 only. but for other numbers its working. ex. 371, 1634,... please any1 can explain??


thanks for ur support and sorry for poor english


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: problem with compiler or my code ???
« Reply #1 on: November 28, 2017, 05:22:30 pm »
1) Hello in the forum
2) Please use code tags if you post code/ logs. Use the # symbol in the new post editor for this.
3) You have a general programming (or maybe even algorithm) question. This forum does not support this kind of questions. You will have to go go stack overflow or any other programming forum for help. This forum supports only questions regarding codeblocks directly (note: codeblocks is not a compiler nor a programming language, but a better text editor that supports multiple compilers).
4) If you are posting this to an other forum, i would suggest that you describe what the program should do and not only "it does not work". If you solve a mathematical problem write the formula you want to use. This is not how you ask intelligent questions. Read this to get help (it is translated in multiple language) http://www.catb.org/esr/faqs/smart-questions.html#translations

good luck
« Last Edit: November 28, 2017, 05:24:20 pm by BlueHazzard »