程序人生——苏嵌第三天

苏嵌教育                                                                     暑期实习


                                          学习日志                                            姓名:胡昊          日期:2018.7.18



                                                

  • 今日学习任务:                                 学习数组,数据类型,指针,函数,字符串。

  • 今日任务完成情况:                         基本完成任务。主要代码:
/*************************************************************************
	> File Name: work5.c
	> Author: HuHao
	> Mail: [email protected] 
	> Created Time: 2018年07月18日 星期三 19时42分17秒
 ************************************************************************/
//递归方法求1的阶乘到N的阶乘之和。
#include <stdio.h>

//递归函数
int digui(int n)
{
	if(n==0)
		return n;
	else
		return digui(n-1)+n;
}

int main()
{
	int n=100,result=0;
	result=digui(n);
	printf("result = %d\n",result);
	return 0;
}
/*************************************************************************
	> File Name: work4.c
	> Author: HuHao
	> Mail: [email protected] 
	> Created Time: 2018年07月18日 星期三 19时26分19秒
 ************************************************************************/
//二维数组的行指针、列指针遍历数组。
#include <stdio.h>
int main()
{
	int i=0,j=0;
	int a[3][3]={1,2,3,4,5,6,7,8,9};
	int (*p)[3]=a;
	printf("遍历数组:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			printf("%d\t",a[i][j]);
		}
		printf("\n");
	}
	printf("指针遍历数组:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			printf("%d\t",*(*(p+i)+j));
		}
		printf("\n");
	}
	return 0;
}
/*************************************************************************
	> File Name: work1.c
	> Author: HuHao
	> Mail: [email protected] 
	> Created Time: 2018年07月18日 星期三 18时19分19秒
 ************************************************************************/
//不借助第三个变量,实现两个变量的交换。
#include <stdio.h>
int main()
{
	int a,b;
	printf("Please input a and b:");
	scanf("%d%d",&a,&b);
	a=b-a;
	b=b-a;
	a=a+b;
	printf("a = %d\n",a);
	printf("b = %d\n",b);
	return 0;
}
/*************************************************************************
	> File Name: work3.c
	> Author: HuHao
	> Mail: [email protected] 
	> Created Time: 2018年07月18日 星期三 18时57分36秒
 ************************************************************************/
//二维数组实现矩阵A、B乘积。
#include <stdio.h>
int main()
{
	int i=0,j=0;
	int a[3][3]={1,2,3,4,5,6,7,8,9};
	int b[3][3]={9,8,7,6,5,4,3,2,1};
	int c[3][3]={0};
	printf("a Array:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
			printf("%d\t",a[i][j]);
		printf("\n");
	}
	printf("b Array:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
			printf("%d\t",b[i][j]);
		printf("\n");
	}
	printf("After the A and B multiplied,");
	printf("c Array:\n");
	for(i=0;i<3;i++)
	for(j=0;j<3;j++)
	{
		c[i][j]=(a[i][0]*b[0][j])+(a[i][1]*b[1][j])+(a[i][2]*b[2][j]);
	}
	printf("c Array:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
			printf("%d\t",c[i][j]);
		printf("\n");
	}
	return 0;
}
/*************************************************************************
	> File Name: work2.c
	> Author: HuHao
	> Mail: [email protected] 
	> Created Time: 2018年07月18日 星期三 18时32分18秒
 ************************************************************************/
//编程实现整型一维数组排序(冒泡排序、改进冒泡排序)
#include <stdio.h>
int main()
{
	//冒泡排序
	int a[10]={1,3,4,2,8,6,9,5,0,7};
	printf("Common sort,");
	printf("Before sort:\n");
	for(int i=0;i<10;i++)
		printf("%d\t",a[i]);
	printf("\n");
	for(int i=0;i<9;i++)
	{
		for(int j=i+1;j<=9;j++)
		{
			if(a[i]<a[j])
			{
				int temp;
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	printf("After sort:\n");
	for(int i=0;i<10;i++)
		printf("%d\t",a[i]);
	printf("\n");
	printf("\n");
	//改进冒泡排序
	printf("Improve sort,");
	printf("Before sort:\n");
	for(int i=0;i<10;i++)
		printf("%d\t",a[i]);
	printf("\n");
	for(int i=0;i<9;i++)
	{
		for(int j=8;j>=i;j--)
		{
			if(a[j]>a[j+1])
			{
				int temp;
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
		}
	}
	printf("After sort:\n");
	for(int i=0;i<10;i++)
		printf("%d\t",a[i]);
	printf("\n");
	return 0;
}

  • 今日开发中出现的问题汇总:         指针的使用,数组指针的使用,算法的编写。

  • 今日未解决问题:                             指针的使用尚有不足,算法编写不熟练。

  • 自我评价:                                         今日温习了c语言,补足了以前c语言的盲点。同时,加深了对vim操作的理解。算是有所收获。

  • 其他:                                                  无
发布了9 篇原创文章 · 获赞 2 · 访问量 652

猜你喜欢

转载自blog.csdn.net/a45654645/article/details/81104855
今日推荐