C语言学习笔记 第四章

4-11-1

#include <stdio.h>
int main(void)
{
	char f_name[30];
	char l_name[30];
	printf("Please enter your first name:");
	scanf("%s",f_name);
	printf("Please enter your last name:");
	scanf("%s",l_name);
	printf("So, your first name is %s and your last name is %s.", f_name, l_name);
	return 0;
}

4-11-2

#include <stdio.h>
int main(void)
{
	char name[40];
	printf("Please enter your name:");
	scanf("%s", name);
	printf("\"%s\"\n", name);
	printf("\"%20s\"\n", name);
	printf("\"%-20s\"\n", name);
	printf("\"%*s\"\n", strlen(name)+3, name);
	return 0;
}

4-11-3

#include <stdio.h>
int main(void)
{
	float num;
	printf("Please enter a float:");
	scanf("%f", &num);
	printf("The input is %f or %e.\n", num, num);
	return 0;
}

4-11-4

#include <stdio.h>
int main(void)
{
	float tall;
	printf("How tall are you in centimeter?\n");
	scanf("%f",&tall);
	tall = tall / 100;
	printf("Dabney, you are %.3f m tall.\n", tall);
	return 0;
}

4-11-5

#include<stdio.h>
int main(void)
{
	char fname[40], lname[40];
	printf("First name:");
	scanf("%s",fname);
	printf("Last name:");
	scanf("%s",lname);
	printf("%s %s\n", fname, lname);
	printf("%*d %*d\n", strlen(fname), strlen(fname), strlen(lname), strlen(lname));
	printf("%s %s\n", fname, lname);
	printf("%-*d %-*d\n", strlen(fname), strlen(fname), strlen(lname), strlen(lname));
	return 0;
}

4-11-6

#include<stdio.h>
#include<float.h>
int main()
{
	double dnum;
	float fnum;
	dnum = 1.0/3.0;
	fnum = 1.0/3.0;
	printf("%.4f %.12f %.16f \n%.4f %.12f %.16f \n", dnum, dnum, dnum, fnum ,fnum, fnum);
	printf("%f\n%f\n", FLT_DIG, DBL_DIG);
	return 0;
}

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