Anonymous
Anonymous
Doesn't enter for loop
Anonymous
Any wrong in it?
Anonymous
Can anyone explain that issue?
Talula
Can anyone explain that issue?
Reading one line at a time is really hard.
Foxner
What kind of output do you want to get? If I read the code correctly, 352 would output three zero zero zero ...
Anonymous
I want three five two and then stop
Anonymous
I am not finding out that whay it's printing zero zero... Looks i have learnt something wrong
Foxner
Yeah, but that won't happen
Foxner
Think about what happens in the loop. In the end you're left with 3.52, you subtract 3, and now you're left with 0.52. The number is greater than zero, so the program stays in the loop, but you don't modify it anymore, and casting it to an integer results in a 0.
Foxner
Then you do 0.52 - 0 = 0.52 and the infinite loop continues
Anonymous
Oo thanks
Swastik
Hey
Anonymous
Which is 5.2
Anonymous
Why then also same output
Anonymous
Zero zero zero
Anonymous
...
klimi
3.52%3.0
klimi
Wait no
klimi
Thats modulo
klimi
*10.0
Anonymous
Hmm
Anonymous
(3.52-3)*10 = 5.2
Anonymous
Assgining to int should give 5
Anonymous
Have to put 10.0 instead of 10?
Foxner
Hey but i did (3.52-3)*10
update the code and send the link
Anonymous
Float i mentioned
Anonymous
But giving input 352
Anonymous
https://pastebin.com/FX1yvUek
Anonymous
float n=36.5228; while(n!=(int)n) { n*=10; } int n1=(int)n; @jimikudo What if u used something like this to remove the decimal, and it's easy from there.
Anonymous
But my problem is can't figure out my code flaw
Anonymous
Run it on conpiler and doba dry run different results
Jhagrut
#include <stdio.h> #include <stdbool.h> int main() { int p,num,i,j; scanf("%d", &num); bool prime[num+1]; for (int j=2; j<=num; j++) { prime[j]=true; } for (p=2; (p*p)<=num; p++) { if (prime[p] == true) { for (i=p*p; i<=num; i += p) prime[i] = false; } } for (p=2; p<=num; p++) if(prime[p]) { printf("%d ", p); } return 0; } i got it tyvm
Talula
I mean I don’t understand the point of the program.
Jhagrut
Anonymous
I want to know what was flaw in my code as it's giving wrong output...
Anonymous
int inp; int inpt=inp,s=0; while(inp >0) { int c=1; while (inpt>9) { inpt/=10; c*=10; } int digit=inpt; //Your shit case here s+=inpt*c; inpt=inp-s; }
Anonymous
This way without using float
Anonymous
@jimikudo Idk why, but the control isn't getting inside the for loop. Put a printf there and check.
Anonymous
Wrong output
Anonymous
😑
Anonymous
I am frustrated i believe it's a memory issue
Talula
I am frustrated i believe it's a memory issue
Yes I have your code but I don’t know what you expect to get out… for example if I put 23… what output should I expect?
Anonymous
Two three
Talula
Okay.
Foxner
Two three
What is the output at the moment?
Anonymous
Zero zero zero........
Anonymous
https://pastebin.com/bGTrPBNm
Anonymous
hmm
Anonymous
output if I input 23
Anonymous
how at last float becoming 9.999995? definitely it's something regarding c handles memory
Talula
Okay try this it works.
Talula
https://pastebin.com/iafhVDw0
Anonymous
hmm thanks
Anonymous
I think I need to write in detail in code with every step in comment
Anonymous
int *p; int c=1; p=&c; printf("%d",*p); v/s int *p; p=1; printf("%d",p); Both the codes print 1. I thought that the second would give an error. I don't understand why it works. Any ideas? Note that in the second code, printf doesn't need * before p.
Foxner
how at last float becoming 9.999995? definitely it's something regarding c handles memory
There certainly seem to be a flaw in you program logic, but you're also delaing with floating point precision error here.
Sarbas__ibrahim
I am a beginner and how to study programming
Foxner
How to fix floating point precision error in my case
One simple solution would be to have a vector (or an array of adequate size), then store the digits in reverse by using modulo.
Anonymous
Yep
Anonymous
But it's mentioned to do using previously taught things wich doesn't include an array
Anonymous
Any way great community thanks for helping guys
Foxner
https://en.wikipedia.org/wiki/Double_dabble