//递归的迭代:求n的阶层(不考虑溢出)

// 循环

int fac1(int n)

{

	int ret = 1;

	int i = 0;

	for (i = 1; i <= n; i++)

	{

  ret *= i;

	}

	return ret;

}

int main()

{

	int n = 0;

	int ret = 0;

	scanf("%d", &n);

	ret = fac1(n);

	printf("%d", ret);

	return 0;

}

//递归

int fac2(int n)

{

	if (n <= 1)

  return 1;

	else

  return n * fac2(n - 1);


}

int main()

{

	int n = 0;

	int ret = 0;

	scanf("%d", &n);

	ret = fac2(n);

	printf("%d", ret);

	return 0;

}

//斐波那契数列

// 递归

int count = 0;

int Fib(int n)

{

	if (n <= 2)

  return 1;

	else

  return Fib(n - 1) + Fib(n - 2);

}

int main()

{

	int n = 0;

	int ret = 0;

	scanf("%d", &n);

	//ADD-测试q驱动开发

	ret = Fib(n);

	printf("ret=%d", ret);

	return 0;

}

//循环

int Fib(int n)

{

	int a = 1;

	int b = 1;

	int c = 1;

	while (n > 2)

	{

  c = a + b;

  a = b;

  b = c;

  n--;

	}

	return c;

}

int main()

{

	int n = 0;

	int ret = 0;

	scanf("%d", &n);

	//ADD-测试驱动开发

	ret = Fib(n);

	printf("ret=%d", ret);

	return 0;

}


//自主练习

//1.青蛙跳台阶问题--《剑指offer》笔试题

//2.汉诺塔问题--广联达


#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

#include<string.h>

//数组:相同类型元素的结合

//创建-初始化

int main()

{

	char arr[] = "abcdef";

	printf("%d\n", sizeof(arr));//求得是所占空间的大小。可以计算变量、数组、类型的大小--这是一个操作符

	printf("%d\n", strlen(arr));//计算字符串的长度,当读到\0时就截止,并且不计算\0。只能求字符串的长度。--库函数--需要引用头文件

	return 0;

}


//一维数组的使用

//下标引用操作符

int main()

{

	char arr[] = { "abcdef" };

	int len = strlen(arr);

	int i = 0;

	for (i = 0; i < len; i++)

	{

  printf("%c\n", arr[i]);

	}

	return 0;

}

int main()

{

	char arr[] = { 1,2,3,4,5,6,7,8,9,0 };

	int sz = sizeof(arr) / sizeof(arr[0]);

	int i = 0;

	for (i = 0; i < sz; i++)

	{

  printf("%d\n", arr[i]);

	}

	return 0;

}

//取地址

int main()

{

	int arr[] = { 1,2,3,4,5,6,7,8,9,0 };//数组在内存中是连续存放的

	int sz = sizeof(arr) / sizeof(arr[0]);

	int i = 0;

	for (i = 0; i < sz; i++)

	{

  printf("arr[%d]=%p\n",i, &arr[i]);

	}

	return 0;

}

//二维数组的创建和初始化使用

//行下标可以省略,列不可以

//打印元素

int main()

{

	int arr[3][4] = { {1,2,3},{4,5,6},{7,8,9,1} };

	int i = 0;

  
	for (i = 0; i < 3; i++)

	{

  int j = 0;

  for (j = 0; j < 4; j++)

  {

  	printf("%d ", arr[i][j]);

  }

  printf("\n");

	}

	return 0;

}

//打印地址,二维数组在内存中也是连续存放的

int main()

{

	int arr[3][4] = { {1,2,3},{4,5,6},{7,8,9,1} };

	int i = 0;


	for (i = 0; i < 3; i++)

	{

  int j = 0;

  for (j = 0; j < 4; j++)

  {

  	printf("arr[%d][%d]=%p\n", i,j,&arr[i][j]);

  }

	}

	return 0;

}