• C


    函数与指针

    #include <stdio.h>
    
    double min(double x, double y);
    void chline(char ch[], int  i, int j);
    void to_binary(int i);
    long fibonacci(int n);
    void swap(int* a, int* b);
    
    
    int main()
    {
    	printf("计算最小值(2.0,2.01) = %5.2f 
    ", min(2.0, 2.01));
    	char ss[50] = "beautiful";
    	printf("指定输出 beautiful 1,3 = ");
    	chline(ss, 1, 3);
    	printf("
     10进制转2进制: 100 =");
    	to_binary(100);
    
    	printf("
     打印斐波那契数列第n个:");
    	long fb = fibonacci(5);
    	printf("fb = %ld 
     ", fb);
    
    	printf("通过指针交换 
    ");
    	int a = 1, b = 2;
    	printf("before, a=%d ,b=%d 
    ", a, b);
    	swap(&a, &b);
    	printf("after , a=%d ,b=%d 
    ", a, b);
    
    	return 0;
    }
    
    double min(double x, double y)
    {
    	return x < y ? x : y;
    }
    
    void chline(char ch[], int i, int j)
    {
    	for (; i <= j; i++) {
    		printf("%c", ch[i]);
    	}
    	printf("
    ");
    }
    
    void to_binary(int i)
    {
    	int mod = i % 2;
    	int shang = i / 2;
    	if (1 == shang)printf("%d", shang);
    	else if (shang > 1)to_binary(shang);
    	printf("%d", mod);
    }
    
    long fibonacci(int n)
    {
    	if (n > 2) 
    		return fibonacci(n - 1) + fibonacci(n - 2);
    	return 1;
    }
    
    void swap(int * a, int * b)
    {
    	int* temp;
    	temp = *a;
    	*a = *b;
    	*b = temp;
    }
    
    
    

    数组与指针

    #include <stdio.h>
    
    printf_array(int array[][3], int row, int col);
    printf_vla(int rows, int cols, int ar[rows][cols]); // 变长数组VLA ,C99支持
    
    int main()
    {
    	int days[] = { 1,3,10 };
    	for (int i = 0; i < sizeof days / sizeof days[0]; i++)
    		printf("index : %d , value : %d 
    ", i, days[i]);
    
    	int matrix1[2][3] = {
    		{1,2,3},
    		{1,4,3}
    	};
    	 // 二维数组打印
    	printf_array(matrix1, 2, 3);
    	
    	return 0;
    }
    
    printf_array(int array[][3], int row, int col)
    {
    	for (int i = 0; i < row; i++)
    	{
    		for (int j = 0; j < col; j++)
    		{
    			printf("%d,", *(*(array + i) + j));
    		}
    		printf("
    ");
    	}
    
    }
    
    
    
  • 相关阅读:
    小希的迷宫(hdu1272 并查集)
    How many Fibs?(poj 2413)大数斐波那契
    图练习-BFS-从起点到目标点的最短步数(sdut 2830)邻接边表
    最大流(EK)
    趣写算法系列之--匈牙利算法(真的很好理解)
    Saving Princess claire_(hdu 4308 bfs模板题)
    Knight Moves(hdu1372 bfs模板题)
    The Die Is Cast(poj 1481简单的双dfs)
    Oil Deposits(poj 1526 DFS入门题)
    WTL:下载、安装、初见
  • 原文地址:https://www.cnblogs.com/hiqianqian/p/6816170.html
Copyright © 2020-2023  润新知