C语言学习笔记——第六章

6-1.c

#include<stdio.h>
int main(void)
{
	char letter[27]="abcdefghijklmnopqrstuvwxyz";
	int a;
	for(a=0 ; a<26; a++)
		printf("%c", letter[a]);
	return 0;
}

6-10.c

#include&lt;stdio.h&gt;
int main(void)
{
	int integer[8];
	int a,b;
	printf("Please input 8 integers:");
	for(a=0;a&lt;8;a++)
		scanf("%d",&integer[a]);
	for(a=7;a&gt;-1;a--)
		printf("%d ",integer[a]);
	return 0;
}

	

6-11.c

#include&lt;stdio.h&gt;
float run1(int towhere);
float run2(int towhere);
int main(void)
{
	float a;
	printf("To:");
	scanf("%f", &a);
	printf("%f\n",run1(a));
	printf("%f\n",run2(a));
	return 0;
}
float run1(int towhere)
{
	float a,b=1.0;
	for (a=2.0;a&lt;=towhere;a++)
		b+=1.0/a;
	return b;
}
float run2(int towhere)
{
	float a,b=1.0;
	for (a=2.0;a&lt;=towhere;a++)
		b+=(((int)a-1)%2==0?1:-1)*(1.0/a);
	return b;
}


6-12.c

#include<stdio.h>
long pow(int num, int times);
int main(void)
{
	int number[8];
	int a;
	for(a=0;a<8;a++)
	{
		number[a]=pow(2,a+1);
	}
	a=0;
	do
		printf("%d\n", number[a]);
	while (++a<8);
	return 0;


}
long pow(int num, int times)
{
	int a;
	long b=1;
	for(a=1;a<=times;a++)
	{
		b*=num;
	}
	return b;
}

6-2.c

#include<stdio.h>
int main(void)
{
	int a,b;
	for (a=1;a<=5;a++)
	{
		for (b=1;b<=5;b++)
			printf("$");
		printf("\n");
	}
	return 0;
}

6-3.c

#include<stdio.h>
int main(void)
{
	int a;
	char b;
	for (a=1;a<=6;a++)
	{
		for (b='F';b>='A';b--)
			printf("%c", b);
		printf("\n");
	}
	return 0;
}

6-4.c

#include&lt;stdio.h&gt;
int main(void)
{
	int blank,howlong,a,b,c;
	char towhere,mid;
	printf("Tell me to go where:");
	scanf("%c",&towhere);
	howlong=(towhere - 'A')*2+1;
	for (a=1;a&lt;=(towhere - 'A'+1);a++)
	{
		blank=towhere-'A'-a+1;
		for(b=1;b&lt;=blank;b++)
			printf(" ");
		for (b=0;b&lt;a-1;b++)
			printf("%c",b+'A');
		printf("%c",'A'+a-1);
		for (c=a-1;c&gt;0;c--)
			printf("%c",'A'+c-1);
		for(b=1;b&lt;=blank;b++)
			printf(" ");
		printf("\n");
	}

	return 0;

}

6-5.C

#include&lt;stdio.h&gt;
int main(void)
{
	int from,to;
	int a;
	printf("From:");
	scanf("%d", &from);
	printf("To:");
	scanf("%d",&to);
	for (a=from;a&lt;=to;a++)
	{
		printf("%d %d %d\n",a,a*a,a*a*a);
	}
	return 0;
}
		

6-6.c

#include<stdio.h>
int main(void)
{
	char string[255];
	int max,where;
	printf("Please input a sentense:");
	scanf("%s",string);
	max=strlen(string) - 1;
	for (where=max;where>=0;where--)
	{
		putchar(string[where]);
	}
	return 0;
}

6-7.c

#include&lt;stdio.h&gt;
float getfloat();
int main(void)
{
	float a,b;
	a=getfloat();
	b=getfloat();
	printf("%f\n",(a-b)/(a*b));
	return 0;

}
float getfloat()
{
	float a=0.0;
	printf("Please input a float:");
	while(scanf("%f",&a) != 1);
	return a;
}

6-9.c

#include&lt;stdio.h&gt;
long dorun(int lower,int upper);
int main(void)
{
	int lower,upper=0;
	printf("Enter lower and upper integer limits:");
	scanf("%d %d",&lower,&upper);
	while (lower&lt;=upper)
	{
		printf("The sums of the squares form %d to %d is %ld.\n",lower,upper,dorun(lower,upper));
		printf("Enter next set of limits:");
		scanf("%d %d",&lower,&upper);
	}
	printf("Done.\n");
	return 0;
}
long dorun(int lower,int upper)
{
	int a=0;
	long c=0;
	for (a=lower;a&lt;=upper;a++)
	{
		c+=a*a;
	}
	return c;
}


原创文章,转载请注明: 转载自YXZ’s Blog

本文链接地址: C语言学习笔记——第六章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>