Skip to content

Instantly share code, notes, and snippets.

@TokisakiKurumi2001
Created March 9, 2020 09:16
Show Gist options
  • Select an option

  • Save TokisakiKurumi2001/65c77a1d7a626affc676f242dbc45ed4 to your computer and use it in GitHub Desktop.

Select an option

Save TokisakiKurumi2001/65c77a1d7a626affc676f242dbc45ed4 to your computer and use it in GitHub Desktop.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int number, res;
String c;
if (Serial.available())
{
c = Serial.readString();
number = c.toInt();
res = reverse_num(number);
Serial.println(res);
}
}
int reverse_num(int num)
{
int digit = 0;
int new_num = 0;
while (num != 0)
{
digit = num % 10;
new_num = new_num * 10 + digit;
num /= 10;
}
return new_num;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment