factorial

Three colors triangles

大城市里の小女人 提交于 2021-02-07 12:52:38
问题 I am trying to make a code for this problem: (Source: https://www.codewars.com/kata/insane-coloured-triangles/train/c) A coloured triangle is created from a row of colours, each of which is red, green or blue. Successive rows, each containing one fewer colour than the last, are generated by considering the two touching colours in the previous row. If these colours are identical, the same colour is used in the new row. If they are different, the missing colour is used in the new row. This is

Three colors triangles

旧巷老猫 提交于 2021-02-07 12:51:47
问题 I am trying to make a code for this problem: (Source: https://www.codewars.com/kata/insane-coloured-triangles/train/c) A coloured triangle is created from a row of colours, each of which is red, green or blue. Successive rows, each containing one fewer colour than the last, are generated by considering the two touching colours in the previous row. If these colours are identical, the same colour is used in the new row. If they are different, the missing colour is used in the new row. This is

Why am I getting a strange number in this code?

房东的猫 提交于 2021-02-05 12:07:53
问题 I want to write a C program that evaluates the factorials of the integers from 1 to 5 and print them in a tabular format. However, I keep getting a strange number over everything. Here's the code: #include <stdio.h> int main() { int factorial; printf("X\t Factorial of X\n"); for(int x=1; x<=5; x++) { factorial = 1; for (int j=1; j<=x; j++) { factorial *=j; } printf("%d\t %d\n", &x, &factorial); } return 0; } Here's the result of this code: X Factorial of X 6356768 6356772 6356768 6356772

Factorial function in x86 NASM assembly goes wrong

会有一股神秘感。 提交于 2021-01-29 01:54:26
问题 I'm learning assembly language using x86 NASM. I wanted to write a simple recursive factorial function to which I am passing one parameter using EAX register. After that, I want to print my result on the screen but nothing happens. After sitting and staring on my computer I don't have any clue what is wrong with my code. Can you guys help newbie with this problem? I know that the prologue and epilogue of factorial funtion is not required due I'm not using stack but for me code is more

How to calculate 21 factorial in Rust?

空扰寡人 提交于 2020-12-13 18:13:09
问题 I need to calculate 21 factorial in my project. fn factorial(num: u64) -> u64 { match num { 0 => 1, 1 => 1, _ => factorial(num - 1) * num, } } fn main() { let x = factorial(21); println!("The value of 21 factorial is {} ", x); } When running this code, I get an error: thread 'main' panicked at 'attempt to multiply with overflow', src\main.rs:5:18 回答1: A u64 can’t hold 21! (it’s between 2^65 and 2^66), but a u128 can. 回答2: I need to calculate 21 factorial in my project. 21! doesn't fit in a 64

How to calculate 21 factorial in Rust?

て烟熏妆下的殇ゞ 提交于 2020-12-13 18:11:32
问题 I need to calculate 21 factorial in my project. fn factorial(num: u64) -> u64 { match num { 0 => 1, 1 => 1, _ => factorial(num - 1) * num, } } fn main() { let x = factorial(21); println!("The value of 21 factorial is {} ", x); } When running this code, I get an error: thread 'main' panicked at 'attempt to multiply with overflow', src\main.rs:5:18 回答1: A u64 can’t hold 21! (it’s between 2^65 and 2^66), but a u128 can. 回答2: I need to calculate 21 factorial in my project. 21! doesn't fit in a 64

How to calculate 21 factorial in Rust?

自闭症网瘾萝莉.ら 提交于 2020-12-13 18:11:04
问题 I need to calculate 21 factorial in my project. fn factorial(num: u64) -> u64 { match num { 0 => 1, 1 => 1, _ => factorial(num - 1) * num, } } fn main() { let x = factorial(21); println!("The value of 21 factorial is {} ", x); } When running this code, I get an error: thread 'main' panicked at 'attempt to multiply with overflow', src\main.rs:5:18 回答1: A u64 can’t hold 21! (it’s between 2^65 and 2^66), but a u128 can. 回答2: I need to calculate 21 factorial in my project. 21! doesn't fit in a 64

How to calculate 21 factorial in Rust?

感情迁移 提交于 2020-12-13 18:09:14
问题 I need to calculate 21 factorial in my project. fn factorial(num: u64) -> u64 { match num { 0 => 1, 1 => 1, _ => factorial(num - 1) * num, } } fn main() { let x = factorial(21); println!("The value of 21 factorial is {} ", x); } When running this code, I get an error: thread 'main' panicked at 'attempt to multiply with overflow', src\main.rs:5:18 回答1: A u64 can’t hold 21! (it’s between 2^65 and 2^66), but a u128 can. 回答2: I need to calculate 21 factorial in my project. 21! doesn't fit in a 64

How to calculate 21 factorial in Rust?

旧城冷巷雨未停 提交于 2020-12-13 18:09:08
问题 I need to calculate 21 factorial in my project. fn factorial(num: u64) -> u64 { match num { 0 => 1, 1 => 1, _ => factorial(num - 1) * num, } } fn main() { let x = factorial(21); println!("The value of 21 factorial is {} ", x); } When running this code, I get an error: thread 'main' panicked at 'attempt to multiply with overflow', src\main.rs:5:18 回答1: A u64 can’t hold 21! (it’s between 2^65 and 2^66), but a u128 can. 回答2: I need to calculate 21 factorial in my project. 21! doesn't fit in a 64

How to calculate 21 factorial in Rust?

蓝咒 提交于 2020-12-13 18:06:53
问题 I need to calculate 21 factorial in my project. fn factorial(num: u64) -> u64 { match num { 0 => 1, 1 => 1, _ => factorial(num - 1) * num, } } fn main() { let x = factorial(21); println!("The value of 21 factorial is {} ", x); } When running this code, I get an error: thread 'main' panicked at 'attempt to multiply with overflow', src\main.rs:5:18 回答1: A u64 can’t hold 21! (it’s between 2^65 and 2^66), but a u128 can. 回答2: I need to calculate 21 factorial in my project. 21! doesn't fit in a 64