xxxx
xxxx
Last edited by blinded; 04-09-2010 at 04:18 PM. Reason: delete
Step 1: Put your code inside code tags. You can either highlight your code and click the # sign in the edit window, or you can type [code] at the beginning of the code and [/code] at the end.
Step 2. Why do you think "it" (whatever or whoever "it" is) has a problem (whatever the problem is, which is unspecified) with the if comparison (whichever of the if comparisons you have in your code)?
#1 Use code tags when posting code. You may have noticed this at the top of the board:
<< !! Posting Code? Read this First !! >>
That does not mean "Posting Code? Ignore this!"
#2 Indent.
#3 Describe the problem.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
> int n;
> int s[n];
What garbage value of n is being used to specify the sizes of these arrays?
There's a 50% chance it's NEGATIVE!
> for (int i=1; i<=n; i++)
Arrays begin at 0, not 1
Oh, and having variables called p and P (differing only by case) will confuse you. Try picking some meaningful names.
For C programming, try using these options (for gcc)
It would throw out a lot of the dubious code you have.Code:gcc -W -Wall -ansi -pedantic -O2 prog.c
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.