C Primer Plus 编程练习代码——第2章
来源:互联网 发布:咫尺网络 编辑:程序博客网 时间:2024/06/10 09:54
1.Write a program that uses one printf() call to print your first name and last name on one line, uses a second printf() call to print your first and last names on two separate lines, and uses a pair of printf() calls to print your first and last names on one line. The output should look like this (but using your name):
#include <stdio.h>int main(void) { printf("Steve Jobs\n"); //print first and last name in one line printf("Steve\nJobs\n"); //print first and last name in seperated lines printf("Steve "); //print first and last name in one line using a pair of printf printf("Jobs"); return 0;}
2.Write a program to print your name and address.(Omitted)
3.Write a program that converts your age in years to days and displays both values. At this point, don't worry about fractional years and leap years.
#include <stdio.h>int main(void) { int ageInYear, ageInDay; ageInYear = 26; ageInDay = ageInYear * 365; printf("My age is %d-year-old, which is %d days", ageInYear, ageInDay); return (0);}
4.Write a program that produces the following output:
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!
Have the program use two user-defined functions in addition to main(): one that prints the "jolly good" message once, and one that prints the final line once.
#include <stdio.h>void myPrint1(void);void myPrint2(void);int main(void) { int i = 1; for(i; i <= 3; i++){ printf("For he's a "); myPrint1(); printf("fellow.\n"); } myPrint2(); return (0);}void myPrint1(void){ printf("jolly good ");}void myPrint2(void){ printf("Which nobody can deny!\n");}
5.Write a program that creates an integer variable called toes. Have the program set toes to 10. Also have the program calculate what twice toes is and what toes squared is. The program should print all three values, identifying them.
#include <stdio.h>int main(void) { int toe = 10; printf("The toe is %d, twice toe is %d, and toe squarded is %d", toe, toe * 2, toe * toe); return 0;}6.Write a program that produces the following output:
Smile!Smile!Smile!
Smile!Smile!
Smile!
Have the program define a function that displays the string Smile! once, and have the program use the function as often as needed.
#include <stdio.h>void smile(void);int main(void) { smile(); smile(); smile(); printf("\n"); smile();smile();printf("\n"); smile(); return 0;}void smile(void){ printf("smile!");}7.Write a program that calls a function named one_three(). This function should display the word one on one line, call the function two(), and then display the word three on one line. The function two() should display the word two on one line. The main() function should display the phrase starting now: before calling one_three() and display done! after calling it. Thus, the output should look like the following:
starting now:
one
two
three
done!
#include <stdio.h>void one_three(void);void two(void);int main(void) { printf("Starting now: \n"); one_three(); printf("Done!"); return 0;}void one_three(void) { printf("one\n"); two(); printf("three\n");}void two(void) { printf("two\n");}
- C Primer Plus 编程练习代码——第2章
- 【C++】学习笔记十四——C++ primer plus第六版第4章编程练习
- c++primer plus 第4章编程练习之路
- C Primer Plus 第9章 函数 编程练习
- C.Primer.Plus(第六版)第10章 编程练习
- C.Primer.Plus(第六版)第11章 编程练习
- C.Primer.Plus(第六版)第12章 编程练习
- C.Primer.Plus(第六版)第13章 编程练习
- C.Primer.Plus(第六版)第14章 编程练习
- C.Primer.Plus(第六版)第15章 编程练习
- C.Primer.Plus(第六版)第16章 编程练习
- C.Primer.Plus(第六版)第17章 编程练习
- 《C Primer Plus(第5版)中文版》第7章编程练习第2题
- 记录——《C Primer Plus(第五版)》 第7章编程练习第5题
- C++ Primer Plus 第2章 编程练习
- c++primer plus 第六版 第2章 编程练习之路
- 记录——《C Primer Plus (第五版)》第十一章编程练习第5-12题
- 记录——《C Primer Plus (第五版)》第十二章编程练习第1-8题
- 【转】用U盘装系统的操作
- Squid + iptables 完美结合
- 【转】PPT精典基础教程
- LDM上层建筑之dev---局部窥探
- C++语言代码检查工具PC-Lint简介
- C Primer Plus 编程练习代码——第2章
- 如何安装svnversion客户端到CentOS(Linux)?
- 【转】Power_Point的使用技巧
- 【转】ppt使用技巧
- Guardian 配置文档
- Window下Apache+Mysql+PHP开发环境配置问题整理
- C++函数重载深度剖析
- 30分钟学会使用jQuery的Ajax功能<一>
- 简单解释 C / C++ 字节对齐