• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /var/www/html/cnasolution/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/index.php
Line: 315
Function: require_once

# include  int main(){     int a,b;     scanf("%d %d",&a,&b);     while (a > 0) {         int digit = a % 10;         //printf("%d ",digit); for testing         a = a - digit;         a /= 10;     }     while (b > 0) {         int digit = b % 10;         //printf("%d ",digit); for testing         b = b - digit;         b /= 10;     } } 

This code takes two integers with the same lengths(a,b), splits them into their characters, now the question is how to print it like this for example(a=123 , b= 798 --> result = 17-29-38

Download script demo [LINK]
Download script demo [LINK 2] Download script demo [LINK 2]
c

Save the digits in arrays. Then you can loop over the arrays to print the digits at the end.

Also, you don't need to subtract digit before dividing by 10, since division discards the remainder.

# include  #define MAXDIGITS 20  int main(){     int a,b;     int adigits[MAXDIGITS], bdigits[MAXDIGITS];     int digits = 0;      scanf("%d %d",&a,&b);     while (a > 0) {         int digit = a % 10;         //printf("%d ",digit); for testing         adigits[digits++] = digit;         a /= 10;     }     digits = 0;     while (b > 0) {         int digit = b % 10;         //printf("%d ",digit); for testing         bdigits[digits++] = digit;         b /= 10;     }     while (--digits >= 0) {         printf("%d%d", adigits[digits], bdigits[digits]);         if (digits != 0) {             putchar('-');         }     }     putchar('
'); } 
see demo
  • 0
Reply Report