TOPIC

Time limit exceeded

Hayla L.P. asked 6 months ago

include

int main() {

char showsum[100]; int num1, num2, sum, i; do { scanf("%d" "%d", &num1, &num2); if(num1 != '0' && num2 != '0') { sum = num1 + num2; sprintf( showsum,"%d", sum);// sprintf

for(i=0; showsum[i] !='\0'; i++) {
  if (showsum[i] != '0'){
  putchar(showsum[i]);
  }
}
 putchar('\n');

} } while(num1 != '0' && num2 != '0'); return 0; }

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 6 months ago

    num1 != '0' && num2 != '0'

    '0' is the ASCII code for the symbol 'digit 0' which is 48:

    printf( "%d\n", '0')

    Please, see https://www.asciitable.com/ If you want to compare some integer variable with 0 you should not use '0' but single 0 instead:

    num1 != 0 && num2 != 0