Anonymous
Anonymous
Doesn't enter for loop
Anonymous
Any wrong in it?
Anonymous
Can anyone explain that issue?
Anonymous
Foxner
What kind of output do you want to get? If I read the code correctly, 352 would output three
zero
zero
zero
...
Anonymous
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
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?
Anonymous
Anonymous
Float i mentioned
Anonymous
But giving input 352
Anonymous
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
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
Anonymous
Talula
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
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
Anonymous
Wrong output
Anonymous
😑
Anonymous
I am frustrated i believe it's a memory issue
Anonymous
Two three
Talula
Okay.
Foxner
Two three
What is the output at the moment?
Anonymous
Zero zero zero........
Anonymous
https://pastebin.com/bGTrPBNm
Jhagrut
Anonymous
hmm
Anonymous
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
Talula
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.
Pacman
Anonymous
Anonymous
Sarbas__ibrahim
I am a beginner and how to study programming
Anonymous
Yep
Anonymous
But it's mentioned to do using previously taught things wich doesn't include an array
Dima
Anonymous
Any way great community thanks for helping guys
Foxner
Foxner
https://en.wikipedia.org/wiki/Double_dabble