Re: programming-challenges
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 13:43:22 +0000
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.
.
- References:
- programming-challenges
- From: Ajinkya
- Re: programming-challenges
- From: Barry
- Re: programming-challenges
- From: Ajinkya
- programming-challenges
- Prev by Date: Re: programming-challenges
- Next by Date: Re: long integer multiplication
- Previous by thread: Re: programming-challenges
- Next by thread: Re: programming-challenges
- Index(es):
Relevant Pages
|