码迷,mamicode.com
首页 > 编程语言 > 详细

C语言程序实验报告Ⅶ

时间:2020-06-02 09:38:38      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:value   center   ever   char s   strong   实验   十六   print   char   

C语言程序实验报告Ⅶ
实验项目:C语言程序设计教程第八章指针实验8.3.1,8.3.2,8.3.3,8.3.3.4
姓名:陈?思杰?????实验地点:寝室?????实验时间:2020.06.02??
——————————————————————————————————————————————————————————

一、实验目的与要求??

??1.掌握指针的概念和定义方式
??2.掌握指针的操作符和指针的运算
??3.掌握指针与数组的关系
??4.掌握指针与字符串的关系
??5.熟悉指针作为函数参数及返回指针的函数
??6.了解函数指针

二、实验的内容??

??1.实验8.3.1指针基础及指针运算

问题的简单描述:指针的基本输入输出运算
实验代码:

/*sy8_1.c*/
#include<stdio.h>
main()
{
	int *p,a,c=3;
	float *q,b;
	p=&a;
	q=&b;
	printf("Please Input the Value of a,b:");
	scanf("%d%f",p,q);//指针p,q输入a,b 
	printf("Result:\n");
	printf("\t%d %f\n",a,b);
	printf("\t%d %f\n",*p,*q);//指针p,q间接输出a,b
	printf("The Address of a,b:%p %p\n",&a,&b);
	printf("The Address of a,b:%p %p\n",p,q);
	p=&c;
	printf("c=%d\n",*p);
	printf("The Address of c:%x %x\n",&c,p);
 } 

问题分析:%p,%x用于输出十六进制的地址值


??2.实验8.3.2数据交换

问题的简单描述:
实验代码:

/*sy8_2.c*/
#include<stdio.h>
void swap1(int x,int y);
void swap2(int *x,int *y);
int main()
{
	int a,b;
	printf("Pleale Input \na=:");
	scanf("%d",&a);
	printf("b=:");
	scanf("%d",&b);
	swap1(a,b);
	printf("After Call swap1:a=%d b=%d",a,b);
	swap2(&a,&b);
	printf("\nAfter Call swap2:a=%d b=%d\n",a,b);
	return 0;	 
}
void swap1(int x,int y)
{
	int temp;
	temp=x;
	x=y;
	y=temp;
}
void swap2(int *x,int *y)
{
	int temp;
	temp=*x;
	*x=*y;
	*y=temp;
}

问题分析:


??3.实验8.3.3字符串反转与字符串连接

问题的简单描述:
实验代码:

/*sy8_ 3.c */
#include<stdio.h>
char *reverse(char *str);
char *link(char *strl, char *str2);
int main()
{
	char str[30],str1[30], *str2;
	printf ("Input Reversing Character String: ");
	gets(str);
	str2=reverse(str);   //反转 
	printf("Output Reversed Character String: ");
	puts(str2);
	printf("Input String1: ");
	gets(str);
	printf("Input String2: ");
	gets(str1);
	str2=link(str,str1) ;//链接 
	printf("Link String1 and String2:");
	puts(str2);
	return 0;
}
char *reverse(char *str)
{
	char *p,*q,temp;
	p=str,q=str;
	while(*p!=‘\0‘)
	p++;
	p--;
	while(q<p)
	{
		temp=*q;
		*q=*p;
		*p=temp;
		q++;
		p--;
	}
	return str;
}
char *link(char *str1,char *str2)
{
	char *p=str1,*q=str2;
	while(*p!=‘\0‘)
		p++;
	while(*q!=‘\0‘)
	{
		*p=*q;
		q++;
		p++;
	}
	*p=‘\0‘;
	return str1;
}

	

问题分析:


??4.实验8.3.4数组元素奇偶排列

问题的简单描述:
实验代码:

/*sy8_ 4.c */
#include<stdio.h>
#define N 10
void arrsort(int a[],int n);
main()
{
	int a[N],i;
	printf("输入: ");
	for(i=0;i<N;i++)
	scanf("%d",&a[i]);
	arrsort(a,N);
	printf("输入: ");
	for(i=0;i<N;i++)
	printf("%d ",a[i]);	
}
void arrsort(int a[],int n)
{
	int *p,*q,temp;
	p=a;
	q=a+n-1;
	while(p<q){
		while(*p%2!=0)
		p++;
		while(*q%2==0)
		q--;
		if(p>q)
		break;
		temp=*p;
		*p=*q;
		*q=temp;
		p++;
		q--;
	}
}


问题分析:


三、实验小结(剖析个人得失)??

回到顶部

C语言程序实验报告Ⅶ

标签:value   center   ever   char s   strong   实验   十六   print   char   

原文地址:https://www.cnblogs.com/csjsdyp/p/13029196.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!