WRITE A PROGRAM THAT REVERSES THE DIGITS OF A 15 DIGIT LONG NUMBER WITHOUT ANY STRING CONVERSION AND ANY LIBRARIES...

WRITE A PROGRAM THAT REVERSES THE DIGITS OF A 15 DIGIT LONG NUMBER WITHOUT ANY STRING CONVERSION AND ANY LIBRARIES OTHER THAN YOUR STANDARD LIBRARY OR ELSE THE BIRB IS GOING TO STAB YOU

fn (123456789012345) -> 543210987654321
fn (103569870346215) -> 512643078965301

Other urls found in this thread:

programmingsimplified.com/c/source-code/c-program-reverse-number
twitter.com/AnonBabble

First number num % 10
Second number (num/10)%10
Third number (num/100)%10
And so on and so forth

reverse_number(number)
#TODO - Reverse number function.

can you explain me why this works?

>hey Sup Forums do my homework for me

You're a fucking idiot, we use a base 10 number system so dividing by 10 removes a digit, the modulo gives remainder when divided by 10

...

fn do_my_hw_pls(n: u128) -> u128 {
panic!("do your own homework you fucking faggot")
}

k thanks desu senpai i didn't know im just a baka

Wow fucking bully this is a friendly nigger hating environment! Reorted!

Without trying it out it is along the lines:
int reverese(int k) {
int res = 0;
while(k != 0) {
res = 10*res + k % 10;
k /= 10;
}
return res;
}

kek

Learn how to do math holy fucking shit

print '123456789012345'[::-1]

You have no business programming then idiot. Try menial work instead.

read the problem fool

Why did you do that moron's homework?

print int(str(123456789012345)[::-1])

>without any string conversion
>str()

Write it in verilog.

what if my language of choice natively treats ints as strings?

Go, write your shitty bash scripts somewhere else.

it was perl

>123456789012345
void rev(int *data, int size)
{
int i = 0, j = size - 1;
int tmp;
while (i < j) {
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
i += 1;
j -= 1;
}
}

Result = 0
While (in > 0){
Result *=10
Result += in %10
In /= 10
}
Return result
>mfw phoneposting

>it's a number not a tab
>using int instead of size_t for the size
>using i and j when only one is actually necessary

git gud

Not a programming language

how retarded can you be

(define (reverse n)
(let f ([n n]
[r 0])
(if (> n 0)
(f (/ n 10) (+ (* r 10) (% n 10)))
r)))

nice googling skillz user

programmingsimplified.com/c/source-code/c-program-reverse-number

int reverese(int k) {
int res = 0;
while(k != 0) {
res = k[strlen[k]-1];
}
return res;
}

this is supposed to be hard?
n00bz nabs

>> WITHOUT ANY STRING CONVERSION AND ANY LIBRARIES OTHER THAN YOUR STANDARD LIBRARY

get stabbed retard

NICE OVERFLOWS FAGGGGGGOTTTTS

>,[>,]+[

li $a1, 123456789012345
xor $a2, $a2, $a2
li $t1, 10
beqz $a1, end
loop:
divu $a1, $t1
mflo $a1
mfhi $t2
mul $a2, $a2, $t1
addu $a2, $a2, $t2
bgtz $a1, loop
end:
j end

BIRDMIN NO

int f(int i)
{
int r = 0;

do r = (r * 10) + i % 10;
while (i /= 10);

return r;
}

>homework thread

>implying
This is just the most straightforward algorithm.

Yeah, I know int is not appropriate here.

don't listen to the haters cutie. just crossdress and drop by /agdg/

number = 15digitlong
number2 = 15digitlong_reverse
print number
if(user pres 1){
number = number2
}
print number1 again.


be smart.

...

why are you yelling at me not OP, he's the one asking the question in the first place

neat

import std.stdio;
import std.math;

void reverseNumber(ulong n) {
for (ulong i = 0; i < 15; i++)
(n / pow(10, i) % 10).write;
writeln;
}

void main() {
123456789012345.reverseNumber;
}

>no other libraries than stdlib

If you can't write your own power function you should kill yourself.

Go ahead, do it then

Why would he?

Also math is a part of the standard library.

fun Int.reverse(): Int =
generateSequence(Pair(this, 0), { (n, _) -> Pair(n / 10, n % 10) })
.drop(1)
.takeWhile { (n, d) -> n > 0 || d > 0 }
.map { (_, d) -> d }
.toList()
.asReversed()
.mapIndexed { i, d -> d * Math.pow(10.toDouble(), i.toDouble()) }
.sum()
.toInt()

println(12045.reverse()) // 54021

I bet you work well with others

Who would ever do their programming homework in Rust?

>t. buttblasted retard

...

I bet you don't work with others at all.

opishere

>u128
Is this 128 bit integers? how much slower they are comparing to 64?

wut is this

code link, plz?

Not the poster, but it looks like a genetic algorithm with a fitness function that looks for sassy language.

FYI, GAs operate using Darwin's Theory of Evolution. Individuals are inserted into the population, they have sex and produce offspring, and the children with more desirable traits are the ones that are more likely to pass on their genetic material.

This shit is used for all sorts of optimization problems.

Sorry, looks for the input string, which happens to be sassy language.

>No recursion
Thank you for your interest in our company, user, but we need someone with a bit more experience. However, we'll keep your resume on file.

Good luck in your endeavors.

import std.stdio;
import std.math;

void reverseNumber(ulong n) {
recurNumber(n, 0);
writeln;
}

void recurNumber(ulong n, ulong i){
if (i < 15) {
(n / pow(10, i) % 10).write;
recurNumber(u, i++)
}
}

void main() {
123456789012345.reverseNumber;
}

But what for?

kek'd

$ perl -e "print scalar reverse 123456789012345"
543210987654321

use arrays

This works too:
import std.stdio;
import std.math;

void reverseNumber(ulong n, ulong i = 0) {
if (i == 15) {
writeln;
return;
}
(n / pow(10, i) % 10).write;
return reverseNumber(n, ++i);
}

void main() {
123456789012345.reverseNumber; // 543210987654321
}

Rate:
proc reverseNumber
over 1 < @return if
10 *
over 10 % +
swap 10 / swap
reverseNumber
end

getln 0
reverseNumber
println