Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>to solve this problem ,you can subtract <code>48</code> from <code>i</code> every time you use value of variable <code>i</code> to assign it to the variables of your algorithm : <code>a</code>,<code>b</code>,<code>c</code>,<code>d</code> , in this case the answer to your example 560316 will be 11 ,and I believe it's the largest sum of 3 consecutive digits, That will work because <code>48</code> is the ascii code of the digit 0 ,49 is for the digit 1 and so on, so your code should be like this :</p> <pre><code> #include &lt;stdio.h&gt; int isempt(int a) { if ((a==' ')||(a=='\n')||(a=='\t')) { return 1; } else return 0; } void main() { int a, b, c, d, e, i, maxsum; a = 0; b = 0; c = 0; d = 0; maxsum = 0; i = 0; int counter = 0; //the variables "numsearch" and "inside" indicate whether program is in the number or outside it int numsearch = 1; int inside = 0; while ((i = getchar())!=EOF) { if (numsearch==1) { if (isempt(i)==0) { numsearch = 0; inside = 1; a = i - '0'; counter++; } } else if ((isempt(i)==0)&amp;&amp;(inside==1)) { if (counter == 1) { b = i - '0' ; counter++; } else if (counter == 2) { c = i - '0'; counter++; } else if (counter == 3) { d = i - '0'; maxsum = a+b+c; if ((b+c+d) &gt; maxsum) { maxsum =( b+c+d); } a =b; b = c; c = d; counter++; } else if (counter == 4) { d = i - '0' ; if ((b+c+d)&gt;maxsum) { maxsum = b+c+d; } a=b; b=c; c=d; } } else if ((counter&gt;=3)&amp;&amp;(isempt(i)==1)) { printf("\n%d\n", maxsum ); counter = 0; numsearch = 1; inside = 0; a = 0; b = 0; c = 0; d = 0; } else { counter = 0; numsearch = 1; inside = 0; a = 0; b = 0; c = 0; d = 0; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload