(3)C - 上台阶 easy

简介: (3)C - 上台阶 easy
#include<stdio.h>
int main()
{
  int n;
  int i;
  int f1 = 2, f2 = 1,f3;
  scanf("%d", &n);
    if (n == 2)
      printf("1\n");
    if (n == 3)
      printf("2\n");
    if (n > 2 && n <= 25)
    {
      for (i = 2; i <n-1; i++)
      {
        f3 = f1 + f2;
        f2 = f1;
        f1 = f3;
      }
      printf("%d\n", f3);
    }
  return 0;
}
相关文章
|
6月前
[WMCTF2020]easy_re 题解
[WMCTF2020]easy_re 题解
47 0
|
6月前
|
存储
easy_Maze 题解
easy_Maze 题解
20 1
|
8月前
|
机器学习/深度学习
LeetCode 热题 HOT 100题解 (easy级别)(二)
LeetCode 热题 HOT 100题解 (easy级别)
74 0
|
8月前
|
算法
LeetCode 热题 HOT 100题解 (easy级别)(一)
LeetCode 热题 HOT 100题解 (easy级别)
84 0
|
9月前
|
文件存储
Easy Number Challenge(埃式筛思想+优雅暴力)
Easy Number Challenge(埃式筛思想+优雅暴力)
59 0
|
11月前
|
存储 测试技术 C++
C++/PTA Easy chemistry
In this question, you need to write a simple program to determine if the given chemical equation is balanced. Balanced means that the amount of elements on both sides of the “=” sign is the same.
80 0
Codeforces1486 C1.Guessing the Greatest (easy version)(交互题+二分)
Codeforces1486 C1.Guessing the Greatest (easy version)(交互题+二分)
73 0
codeforces327——A. Flipping Game(前缀和)
codeforces327——A. Flipping Game(前缀和)
63 0
斐波那契数列--别样的解法--O(N)
在使用递归来求斐波那契数列时,可以发现,在这个过程中我们重复计算了一些值,如下图所示,很多值都计算过了,但在递归过程我们没有做其他的操作,所以就只能重复的算下去,那如果我们将计算的值保存下来,在进行递归时能够查找到计算过的值,就直接调用而不用重复的计算了
斐波那契数列--别样的解法--O(N)
Leetcode-Easy 728. Self Dividing Numbers
Leetcode-Easy 728. Self Dividing Numbers
73 0
Leetcode-Easy 728. Self Dividing Numbers