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
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.
>>60559018
can you explain me why this works?
>hey /g/ do my homework for me
>>60559227
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
>>60558946fn do_my_hw_pls(n: u128) -> u128 {
panic!("do your own homework you fucking faggot")
}
>>60559251
k thanks desu senpai i didn't know im just a baka
>>60559251
Wow fucking bully this is a friendly nigger hating environment! Reorted!
>>60558946
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;
}
>>60559060
kek
>>60559272
Learn how to do math holy fucking shit
print '123456789012345'[::-1]
>>60559272
You have no business programming then idiot. Try menial work instead.
>>60559314
read the problem fool
>>60559285
Why did you do that moron's homework?
>>60559349print int(str(123456789012345)[::-1])
>>60559375
>without any string conversion
>str()
Write it in verilog.
>>60559406
Go, write your shitty bash scripts somewhere else.
>>60558946
>123456789012345void 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
>>60559459
>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
>>60559401
Not a programming language
>>60559227
how retarded can you be
>>60558946(define (reverse n)
(let f ([n n]
[r 0])
(if (> n 0)
(f (/ n 10) (+ (* r 10) (% n 10)))
r)))
>>60559285
nice googling skillz anon
http://www.programmingsimplified.com/c/source-code/c-program-reverse-number
>>60558946int reverese(int k) {
int res = 0;
while(k != 0) {
res = k[strlen[k]-1];
}
return res;
}
this is supposed to be hard?
n00bz nabs
>>60560177
>> WITHOUT ANY STRING CONVERSION AND ANY LIBRARIES OTHER THAN YOUR STANDARD LIBRARY
get stabbed retard
>>60560177
>>60559285
NICE OVERFLOWS FAGGGGGGOTTTTS
>,[>,]+[<.]
>>60558946li $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
>>60558946
BIRDMIN NO
>>60558946int f(int i)
{
int r = 0;
do r = (r * 10) + i % 10;
while (i /= 10);
return r;
}
>>60558946
>homework thread
>>60560106
>implying
This is just the most straightforward algorithm.
>>60560306
Yeah, I know int is not appropriate here.
>>60559272
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.
>>60559251
>>60559980
>>60559293
>>60559346
>>60560976
why are you yelling at me not OP, he's the one asking the question in the first place
>>60559018
neat
>>60558946
>>60559018import 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;
}
>>60561799
>no other libraries than stdlib
>>60561814
If you can't write your own power function you should kill yourself.
>>60561822
Go ahead, do it then
>>60561832
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
>>60559251
I bet you work well with others
>>60559271
Who would ever do their programming homework in Rust?
>>60562619
>t. buttblasted retard
>>60563322
I bet you don't work with others at all.
>>60558946
>>60559253
opishere
>>60559227
>>60561502
>>60559018
>>60559271
>u128
Is this 128 bit integers? how much slower they are comparing to 64?
>>60563451
wut is this
>>60563451
code link, plz?
>>60563893
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.
>>60563963
Sorry, looks for the input string, which happens to be sassy language.
>>60561799
>No recursion
Thank you for your interest in our company, anon, but we need someone with a bit more experience. However, we'll keep your resume on file.
Good luck in your endeavors.
>>60564029import 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?
>>60559060
kek'd
$ perl -e "print scalar reverse 123456789012345"
543210987654321
>>60558946
use arrays
>>60564326
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