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

5-1.c

#include<stdio.h>
const int n60 = 60;
int main(void)
{
	int i_input, i_min, i_hour;
	printf("Change min into hour+min.\n");
	printf("Input <=0 to stop.\n");
	printf("Input a minute:");
	scanf("%d", &i_input);
	while(i_input > 0)
	{
		i_hour = i_input / n60;
		i_min = i_input % n60;
		printf("%d min is %d hour(s) and %d i_minute(s).\n", i_input, i_hour, i_min);
		printf("Input a minute:");
		scanf("%d", &i_input);
	}
	printf("Done!");
	return 0;
}

5-2.c

#include<stdio.h>
int main(void)
{
	int i, num;
	printf("Please input an int:");
	scanf("%d", &num);
	i = 0;
	while(i++ < 11)
	{
		printf("%d ", num + i-1);
	}
	printf("\nDone!\n");
	return 0;
}

5-3.c

#include<stdio.h>
const int n7 = 7;
int main(void)
{
	int i_input, i_min, i_hour;
	printf("Change days into weeks+days.\n");
	printf("Input <=0 to stop.\n");
	printf("Input a days:");
	scanf("%d", &i_input);
	while(i_input > 0)
	{
		i_hour = i_input / n7;
		i_min = i_input % n7;
		printf("%d day is %d week(s) and %d day(s).\n", i_input, i_hour, i_min);
		printf("Input a day:");
		scanf("%d", &i_input);
	}
	printf("Done!");
	return 0;
}

5-5.c

#include<stdio.h>
int main(void)
{
	int i, i_num=0, towhere;
	printf("Input an int:");
	scanf("%d", &towhere);
	printf("How much is 1+2+3+...+%d?.\n", towhere);
	i = 0;
	while(i++ < towhere)
	{
		i_num = i_num+i;
	}
	printf("Oh, it's %d.\n", i_num);
	return 0;
}

5-6.c

#include<stdio.h>
int main(void)
{
	int i, i_num=0, towhere;
	printf("Input an int:");
	scanf("%d", &towhere);
	printf("How much is 1*1+2*2+...+%d*%d?\n", towhere, towhere);
	i = 0;
	while(i++ < towhere)
	{
		i_num = i_num+i*i;
	}
	printf("Oh, it's %d.\n", i_num);
	return 0;
}

5-7.c

#include<stdio.h>
float sqr(float num);
int main(void)
{
	float f_num;
	printf("Input a float:");
	scanf("%f", &f_num);
	printf("%f * %f is %f",f_num, f_num, sqr(f_num));
	return 0;
}
float sqr(float num)
{
	return num*num;
}

原创文章,转载请注明: 转载自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>