473,320 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

can anyone find the logical error in my program

the question is
Take a number, x, find its factorial, remove the zeroes, and find the last digit.
#include<stdio.h>
#include<math.h>
int main()
{
long long int p,r;
int m,n,i,j;
scanf("%d",&m);
for(i=0;i<m;i++)
{
long long int s=1;
int count=1;
scanf("%d",&n);
if(n==0)
printf("1\n");
else
{
while(n>0)
{
if((n%5)==0)
{
count++;
}
s=s*n;
n--;
}
p=pow(10,count);
// printf("%lld\n",p);
r=s%p;
printf("%d\n",r);
}
}
return 0;
}
Mar 1 '15 #1
1 1231
weaknessforcats
9,208 Expert Mod 8TB
What's not working? Use your debugger and step through the code.

I see a weakness where you use the pow() function because that function uses doubles. An int can be converted to a double but a double cannot be converted to an int due to loss of the decimal places. So the return value cannot be reliable assigned to an int.
Mar 1 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
10
by: Chris | last post by:
Could anyone write a small program to log the Signal-to-Noise figures for a Netgear DG834 router? I have been getting very variable SNR readings - and I would like to collect some evidence to...
3
by: Denny Schierz | last post by:
hi, i have a logical error in my css file, but i don't no where. have a look: http://lippelt-back.com/fileadmin/template/css/new-body.css i comment this lines:
4
by: GRoll21 | last post by:
The problem starts during my while loop. It checks to see if they hit x or X. If they did, then that means the user wants to exit. Then should go on and hit the return statement. It just quits....
19
by: ashmangat | last post by:
Hi! now on the chapter "string-class" My assignment is below Word Counter: Write a function that accepts a pointer to a C-String as an argument and returns the number of words contained in the...
10
by: spacebebop | last post by:
#include <cstring> #include <iostream> using namespace std; class X { public: X(); X( char * ); ~X();
2
by: gnanapoongothai | last post by:
what is logical error found in the code below .Could any find. If( (x!=3) || (x!=4) ) printf("something"); else printf("something") thanks in advance for your answers.
3
by: anchitgood | last post by:
I have tried a lot but unable to correct just 1 logical error in the following code. This error is in the for loop, when fine and minutes are printed as the garbage values. Please check it out: ...
4
by: jinnejeevansai | last post by:
i am trying to write a program to solve postfix expression but it is giving runtime error.i tried to debug but i am not getting why is it happening can anyone find out. #include< stdio.h> ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.