C语言学习《C Primer Plus》编程练习第九章

1

#include 
double min(double x,double y)
{
	if(x

2

#include 
void chline(char *ch[100],int i,int j)
{
	printf("第%d行第%d列的字符是:%c",j,i,ch[j-1][i-1]);
}
int main()
{
	int i,j;
	char *ch[100];
	ch[0]="I am a boy.";
	ch[1]="Hahaha.";
	ch[2]="Hehehe.";
	printf("请输入行数:");
	scanf("%d",&j);
	printf("请输入列数: ");
	scanf("%d",&i);
	chline(ch,i,j);
	 
}

3

#include 
void print(char c,int a,int b)
{
	int i,j;
	for(i=0;i

4

#include 
void average(double x,double y)
{
	printf("%lf和%lf的调和平均数为%lf\n",x,y,1/((1/x+1/y)/2));
}

int main()
{
	double x,y;
	printf("请输入两个数并进行调和平均数运算:");
	scanf("%lf %lf",&x,&y);
	average(x,y);
}

5

#include 
void larger_of(double x,double y)
{
	if(x

6

#include 
void sort(double *x,double *y,double *z)
{
	double temp;
	if(*x>*y)
	{
		temp=*y;
		*y=*x;
		*x=temp;
	}
	if(*x>*z)
	{
		temp=*z;
		*z=*x;
		*x=temp;	
	}
	if(*y>*z)
	{
		temp=*z;
		*z=*y;
		*y=temp;	
	}
}
int main()
{
	double x,y,z;
	printf("请输入三个数进行大小排序:");
	scanf("%lf %lf %lf",&x,&y,&z);
	sort(&x,&y,&z);
	printf("排序后结果为:%lf %lf %lf",x,y,z);
}

7

#include 
#include  
int number(char c)
{
	if(c>='A'&&c<='Z')
		c=c+32;
	if(isalpha(c))
	{
		return c-'a'+1;
	}
	else
	{
		return -1;
	}
}
int main()
{
	char c,s[100];
	int judge,i;
	printf("请输入一段话:");
	gets(s);
	for(i=0;i<100;i++)
	{
		c=s[i];
		if(c=='\0')
			break;
		if(c=='\n')
			continue;
		judge=number(c);
		if(judge==-1)
			printf("%c不是字母\n",c);
		else
			printf("%c是字母,在%d位\n",c,judge); 
	}
	
}

11

#include 
int Fibonacci1(int n)  //递归 
{
	if(n<=0)
		return 0;
	else if(n<=2)
		return 1;
	else
		return Fibonacci1(n-1)+Fibonacci1(n-2);
}
int Fibonacci2(int n)   //循环 
{
	int a=1,b=1,result=0,i;
	if(n<=0)
		return 0;
	else if(n<=2)
		return 1;
	else
	{
		for(i=3;i<=n;i++)
		{
			result = a+b;
			a=b;
			b=result;
		}	
		return result;
	}	
} 
int main()
{
	int n;
	printf("请输入一个数字:");
	scanf("%d",&n);		
	printf("斐波那契数列结果为:%d\n",Fibonacci1(n));
	printf("斐波那契数列结果为:%d\n",Fibonacci2(n));
	
} 

 

你可能感兴趣的:(C语言)