/* 2.12_progrm_1.c --- 按照题目要求格式打印*/#include<stdio.h>intmain(void){printf("Gustav Mahler\n");printf("Gustav\nMahler\n");/*注意\n为转义字符*/printf("Gustav ");printf("Mahler\n");return0;}/*******************************************************************/
Gustav Mahler
Gustav
Mahler
Gustav Mahler
2.编写一个程序,打印你的姓名和地址。
略
3.编写一个程序把你的年龄转换成天数,并显示这两个值。这里不用考虑闰年的问题。
/* 2.12_progrm_3.c --- 把年龄转换成天数,并显示这两个值,考虑闰年*/#include<stdio.h>intmain(void){int year;//定义年的整形变量yearint day ;//定义天的整形变量day
year =38;//给year赋值
day = year *365;//计算天数printf("你今年%d岁了,转换成天一共%d天。\n",year,day);return0;}/*******************************************************************/
你今年38岁了,转换成天一共13870天。
4.编写一个程序,生成以下输出:
For he's a jolly good fellow!
For he's a jolly good fellow!
For he's a jolly good fellow!
Which nobody can deny!
/* 2.12_progrm_4.c --- 按照要求格式输出,注意新建自定义函数*/#include<stdio.h>voidjolly(void);//函数声明(注意结尾;号)voiddeny(void);//函数声明(注意结尾;号)intmain(void){jolly();//函数调用deny();//函数调用return0;}voidjolly(void)//函数定义(注意结尾没有;号){printf("For he's a jolly good fellow!\n");printf("For he's a jolly good fellow!\n");printf("For he's a jolly good fellow!\n");}voiddeny(void)//函数定义(注意结尾没有;号){printf("Which nobody can deny!\n");}/*******************************************************************/
For he's a jolly good fellow!
For he's a jolly good fellow!
For he's a jolly good fellow!
Which nobody can deny!
5.编写一个程序,生成以下输出:
Brazil, Russia, India, China
India, China,
Brazil, Russia
/* 2.12_progrm_5.c --- 按照要求格式输出,注意新建自定义函数*/#include<stdio.h>voidbr(void);//函数声明(注意结尾;号)voidic(void);//函数声明(注意结尾;号)intmain(void){br();//函数调用printf(", ");ic();//函数调用printf("\n");ic();//函数调用printf(",\n");br();//函数调用printf("\n");return0;}voidbr(void)//函数定义(注意结尾没有;号){printf("Brazil, Russia");}voidic(void)//函数定义(注意结尾没有;号){printf("India, China");}/*******************************************************************/
Brazil, Russia, India, China
India, China,
Brazil, Russia
/* 2.12_progrm_8.c --- 按照要求格式输出,注意新建自定义函数*/#include<stdio.h>voidone_three(void);//函数声明(注意结尾;号)voidtwo(void);//函数声明(注意结尾;号)voidthree(void);//函数声明(注意结尾;号)intmain(void){printf("starting now:\n");one_three();//函数调用two();//函数调用three();//函数调用printf("done!\n");return0;}voidone_three(void)//函数定义(注意结尾没有;号){printf("one\n");}voidtwo(void)//函数定义(注意结尾没有;号){printf("two\n");}voidthree(void)//函数定义(注意结尾没有;号){printf("three\n");}/*******************************************************************/
starting now:
one
two
three
done!