You are not logged in. Please login at www.codechef.com to post your questions!

×

# why is it showing error

https://www.codechef.com/problems/DWNLD

# include<stdio.h>

int main() { int t; scanf("%d",&t); while(t--) { int n,i,j=0,k; scanf("%d%d",&n,&k); int t[n],d[n]; for(i=0;i<n;i++) scanf("%d%d",&t[i],&d[i]);="" for(i="0;i&lt;n;i++)" {="" if(k="=0)" break;="" j="j+t[i];" if(j="">k) { t[i]=t[i]-(j-k); break; } else if(j==k) { t[i]=0; break; } else t[i]=0; } int m=0;

for(i=0;i<n;i++)
{
m=m+(t[i]*d[i]);
}
printf("%d\n",m);


} return 0; }

asked 12 Jun '18, 04:56

2★puru15
52
accept rate: 0%

Please format your code using Ctrl + K and then insert your code in it.

(12 Jun '18, 05:02)

 0 okay, alright, first you should have formatted your code, but it's fine, second are those double quotes in the code to point out where the errors are ? because I am confused by those alright, now let's get to it, you have got for( int i = 0; i< ; n ; ++i ) in your second for loop, edit : welp...I know this is a problem, because there can only be two semicolons in the loop, besides, what is the purposeof n in there ? alright, that and in if( j => k ), this is wrong because there is no such expression in C, there are only >= so, the correct way ridiculous, but you need to write it would be if( j >= k ). Ok, as to why it is >= have newline, so instead of =>, is because of how printf( "%d", m ), you need to add "\n", and it is mentioned, which is "greater than or equal", and not "equal or greater than" becomes printf( "%d\n", m ) answered 12 Jun '18, 09:18 2★flaze07 153●6 accept rate: 21% how can I format my code??? and there is no syntax error. My program is running fine in codechef ide. But I think I have missed some cases which is leading to the error... (12 Jun '18, 17:15) puru152★ what do you mean exactly by format ? there are syntax error though, => instead of >=, and the fact that you put three semicolon( ; )s in the for loop (12 Jun '18, 17:28) flaze072★ P.s I put them in codechef ide and I got error (12 Jun '18, 18:40) flaze072★ ok see below codes.... I think it will be ok..... (12 Jun '18, 18:43) puru152★ hmm, I think it is possible for one of the member of the array to become negative, not too sure (12 Jun '18, 21:11) flaze072★
 0 #include int main() { int t; scanf("%d",&t); while(t--) { int n,i,j=0,k; scanf("%d%d",&n,&k); int t[n],d[n]; for(i=0;ik) { t[i]=t[i]-(j-k); break; } else if(j==k) { t[i]=0; break; } else t[i]=0; } int m=0; for(i=0;i
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×151

question asked: 12 Jun '18, 04:56

question was seen: 111 times

last updated: 12 Jun '18, 21:11