# C语言写题目遇到一点问题，求助！

wkr145 2017-12-05 09:52:03

#include "stdafx.h"
long fibonacci(int month)
{
if (month == 3 || month == 2)
{
return 1;
}
else
{
return fibonacci(month - 1) + fibonacci(month - 2);
}
}

int main()
{
int month;
double number;
printf("Please input the moth:"); //*只能输入3到12月份*//
scanf_s("%d", &month);
if (month < 3 || month>12)
{
printf("Enter Error!");
}
number = fibonacci(month);
printf("This you have : %ld", number);
return 0;
}

#include "stdafx.h"
double Jie(int n);

int main()
{
int n;
double result;
printf("Please input the number u want:");
scanf_s("%d", &n);
result = Jie(n);
return 0;
}

double Jie(int n)
{
int i, j;
double a;
a = 1;
for (i = 1;i <= n;i++)
{
for (j = 1;j <= i;j++)
{
a *= j;
}
printf("%d! = %ld\n",i, a);
}
return 0;
}

...全文
180 7 点赞 打赏 收藏 举报

7 条回复

Intel0011 2017-12-07

``````#include <stdio.h>

long Jie(int n);

int main()
{
int n;
long result;
printf("Please input the number u want:");
scanf_s("%d", &n);
result = Jie(n);
return 0;
}

long Jie(int n)
{
int i, j;
long a;
a = 1;
for (i = 1;i <= n;i++)
{
//for (j = 1;j <= i;j++)
{
a *= i;
}
printf("%d! = %ld\n",i, a);
}
return 0;
}
``````
• 打赏
• 举报

• 打赏
• 举报

• 打赏
• 举报

wkr145 2017-12-06

• 打赏
• 举报

weixin_36208943 2017-12-06
double 类型输入用%lf，输出用%f %lf都行。不过你为什么要用double类型，明明计算结果和返回值都是int 类型啊
• 打赏
• 举报

lzb4207123 2017-12-06

• 打赏
• 举报

• 打赏
• 举报

• 打赏
• 举报

C语言

6.5w+

C语言相关问题讨论

2017-12-05 09:52