@Don Which compiler r u using....i m getting d correct o/p for pow as well

On 8/31/11, Don <dondod...@gmail.com> wrote:
> pow works with double (floating point) values, not integers, and when
> you assign the result to an integer, it truncates. You will be better
> off, both in speed and correctness, to just use r*r*r instead of pow(r,
> 3).
> Don
>
> On Aug 30, 1:06 am, Mohit Gupta <mohitgupta.n...@gmail.com> wrote:
>> *1.*
>> /* Print armstrong numbers from 1 to 500 */
>> /*1st version of prgrm: I am using pow function*/
>> #include<stdio.h>
>> #include<conio.h>
>> #include<math.h>
>> int main()
>> {
>> int num=1,temp,sum,r;
>> while(num<=500){
>>   sum=0;
>>   temp=num;
>>   while(temp){
>>     r=temp%10;
>>     sum+=pow(r,3);
>>     temp/=10;
>>   }
>>   if(sum==num)
>>     printf("%d\n",num);
>>   num++;}
>>
>> getch();
>> return 0;
>>
>> }
>>
>> It prints :
>> 1
>> 370
>> 371
>> 407
>>
>> But it does not print 153 which is also armstrong number. WHY???
>>
>> BUT if I change:  pow(r,3) to r*r*r in code....then it prints:
>> 1
>> 153
>> 370
>> 371
>> 407
>>
>> WHY 153 was not printed if i use pow() function???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to