All about problems in Volume CVII. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
by sazzadcsedu » Sun Dec 28, 2008 11:22 pm
whats wrong with my code??
plz someone help.
is my code/algo ok?
- Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
unsigned long long x;
long long n;
long long a,b,c;
int ncase=1;
while(scanf("%llu",&x)==1)
{
if(x==0)
break;
a=1;
b=-3;
c=(-2)*x;
n=(int)((-b+sqrt(b*b-4*a*c))/2*a);
n=n+1;
printf("Case %d: %lld\n",ncase,n);
ncase++;
}
return 0;
}
-
sazzadcsedu
- Experienced poster
-
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
-
by newkid » Mon Dec 29, 2008 3:40 am
i think your solution will fail when x (the input) is 9.
what does your program outputs for that?
hmm..
-
newkid
- Learning poster
-
- Posts: 73
- Joined: Fri Dec 12, 2008 3:06 am
by newkid » Mon Dec 29, 2008 3:43 am
my acc program returns 6 for 9 while your one returns 7
hope it helps
hmm..
-
newkid
- Learning poster
-
- Posts: 73
- Joined: Fri Dec 12, 2008 3:06 am
Return to Volume CVII
Who is online
Users browsing this forum: No registered users and 1 guest