我将使用什么代码来运行此程序 [英] What Code Will I Put To Run This Program
本文介绍了我将使用什么代码来运行此程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <stdio.h>
#include <conio.h>
#DEFINE p = printf, ps = puts;
int getFactorial(int x)
{
//what code will i put here
}
int getFibo(int x)
{
//what code will i put here
}
void printWord(int num)
{
//what code will i put here
}
void main ()
{
int num;
ps("enter a number:");
scanf("%d", &num);
p("Factorial of %d is: %d\n", num, getFactorial(num));
p("Fibonacci of %d is: %d\n", num, getFibo(num));
p("worded value of of %d is: ", num);
PrintWord(num));
}
推荐答案
您知道n
的阶乘定义这种方式(假设n> = 1
)
You know the factorial ofn
is defined this way (assumen>=1
)
fact(n) = n * (n-1) * (n-2) * ... * 1
这意味着
That means
fact(n) = n * fact(n-1)
因此,知道事实(n-1)
让你简单地计算 fact(n)
。使用这个想法你我写了
Hence, knowing fact(n-1)
makes you simply compute fact(n)
. Using this idea you my write
fact(1) = 1
fact(2) = 2 * fact(1) = 2 * 1 = 2
fact(3) = 3 * fact(2) = 3 * 2 = 6
...
fact(n) = n * fact(n-1)
您可以使用简单的循环实现上述操作。
Fibonacci代码稍微详细一点。
You may implement the above operation using a simple loop.
Fibonacci code is just a bit more elaborated.
不,这里不会做家庭作业。
因为那样你会永远无法学到任何东西。
-KR
No, Homework won't be done here.
Because then you will never be able to learn anything.
-KR
你的作业是为了你学习那些东西。所以请学习 Factorials 和 Fibonacci 。
对于措辞,你必须自己建立一个字符串。您需要数字0-9和数百的辅助函数,依此类推。而且工作时,使用%运算符对数字进行反向划分以得到输出的最后一个值,然后用10除以等等。
Your homework is for you learning that stuff. So learn ablout Factorials and Fibonacci.
For the wording you must build a string yourself. You need a helper functions for the digits 0-9 and the "hundreds" and so on. And than work the number reversely divided the with % operator to get last value for output and than divide with 10 and so so.
这篇关于我将使用什么代码来运行此程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文