When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
76 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
@quiet quest
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
hm
yeah, what @fallen cliff said
also, don't do printf("Enter a number: ", N), that N is irrelevant and at best won't do anything
(at worst, it could screw with the stack itself; but virtually every compiler will pass it as a register argument so it wont; but it's possible)
yeah but S+=i, that means 0+1=1 so ,=1
I didn't understand anything :/
i <= N
not necessarily
i doens't start at 0, it starts at an undefined number
since you didnt initialize it, it doesnt start with any particular value
Might be wrong, but I am thinking the OP thinks that
int N, i, S = 0;
Initialises all those variables.
if we said that N is 2 at first , 0 <= 2 it will work then S is 0 at first and S+=i so S has a new variable which is 1 and in this case i will be 1. After that, there is i++, then the new variable of i is gonna be 2. Am I wrong?
and so on
C strikes once again
@quiet quest
Try
int N, i = 0, S = 0;
because C's syntax is not terrific
int N, i, S = 0 is the same as ```c
int N;
int i;
int S = 0;
what is the difference from that, int N, i , S = 0;
because int N, i = 0, s = 0 initializes i too
in this case, we don't know the variables of N and i. Why the outputs work
it doens't
the compiler can do whatever it want, and what it's doing is not what you expect, hence the error
interesting
it is very interesting that there is a rule when the compiler did what ever it wants
what should I do then in this case
just omit , N
it doesn't necessary because we already used scanf, right?
correct, i think you were just confused there
probably need to start i at 1
or:
while (i < N)
either or i think
this is where it becomes math and not c errors, and im not great at math lol
Let N = 3
i will then increment through [0, 1, 2]
yeah
you had the right idea
it's just C being a what, 50, 60 year old langauge? fucked you pu
๐
what about S ๐
I cannot currently answer that question, but counter it with another.
With N = 3, what do you expect S to be in the end?
3+2+1+0= 6
I mean, you said
if we enter 2 as a new variable of N, S should be 2 I think
I am not sure how you arrive at 2.
It would either be 0 + 1 = 1 or 1 + 2 = 3.
You need to tell us what the algorithm is.
We've seen the code, but we have no way of knowing if the code fulfills the requirements of your assignment.
it comes from my teacher's slide
it's just an example
damn
I forgot to write somethings
I'm a fool person sorry guys
but still it had to work ๐
the fact that they put spaces after the function hurts
"until N"
Possibly me, but I find constructs like these ambiguous.
The code is not however.