Re: programming-challenges



Ajinkya said:

On Apr 29, 6:15 am, "Barry" <bar...@xxxxxxxxxxxxxxxxxx> wrote:

Judging by the couple of discussions I looked at on your site,
you have never read c.l.c. Better to shut it down than to
propogate such bad ideas.

Please dont say that to me....there are ACM ICPC winners on the group
who post regularly.

If they're that good, why doesn't their code compile and work properly?

First example I found:

#include <stdio.h>
#include <conio.h>


int main()
{
int TotalSteps=0,NoOfTwoSteps,NoOfOneSteps,TotalWays=1;
int i;


printf ("\nPlease enter the number of steps: ");
scanf ("%d",&TotalSteps);


NoOfTwoSteps=TotalSteps/2;


for (i=1;i<=NoOfTwoSteps;i++)
{
int Factorial1,Factorial2,Factorial3;
int TotalStep,j;
NoOfOneSteps = TotalSteps - i * 2;


Factorial1=Factorial2=Factorial3=1;


for (j=2;j<=NoOfOneSteps+i;j++)
Factorial1*=j;


for (j=2;j<=NoOfOneSteps;j++)
Factorial2*=j;


for (j=2;j<=i;j++)
Factorial3*=j;


TotalStep = Factorial1/(Factorial2*Factorial3);
TotalWays+=TotalStep;
}


printf("\nTotal Ways are: %d",TotalWays);


getch();
return 0;

When we compile this, we get:

foo.c:2: conio.h: No such file or directory
make: *** [foo.o] Error 1

Removing that line, we get:

foo.c:4: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:46: warning: implicit declaration of function `getch'
foo.c:49: parse error at end of input
make: *** [foo.o] Error 1

When we remove the getch and fix the missing brace, we get a program
which behaves thusly:

me@here> ./foo

Please enter the number of steps: ELEPHANT

Total Ways are: 1me@here>

Not good.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.



Relevant Pages

  • xemacs installation problems
    ... checking for gcc... ... checking whether we are using GNU C... ... checking size of int... ... configure: warning: No OffiX without generic Drag'n'Drop support ...
    (comp.os.linux.misc)
  • Re: bug in Real-Time Preemption
    ... lib/rwsem.c:153: warning: type defaults to `int' in declaration of `type name' ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Compile Time Error ... arghh
    ... foo.c:12: warning: function declaration isn't a prototype ... foo.c:13: warning: implicit declaration of function `malloc' ... int ccarray_destroy; ... char *dupstr; ...
    (comp.lang.c)
  • Re: error
    ... foo.c:50: warning: string constant runs past end of line ... foo.c:7: warning: declaration of `n' shadows global declaration ... foo.c:29: warning: return type of `main' is not `int' ... char check(int n_, ...
    (comp.lang.c)
  • 2.6.13-rt14 build problem on Powerpc board
    ... kernel/ntp.c:84: warning: excess elements in scalar initializer ... kernel/ntp.c:104: warning: type defaults to `int' in declaration of ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)