C语言练习题(10)
来源:互联网 发布:如何评价任正非 知乎 编辑:程序博客网 时间:2024/06/05 18:37
1、编写程序:读入一个在字母C和X之间的字符,打印出该字母在中间的相邻五个字母。
如:输入F,则输出DEFGH.
函数原型:void func(char ch)
#include <stdio.h>void func(char ch){ printf("%c%c%c%c%c", ch - 2, ch - 1, ch, ch + 1, ch + 2);}int main(void){ char f; printf("Input a character:"); scanf("%c", &f); func(f); return 0;}
2、一个球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第十次反弹多高。
#include <stdio.h>int main(void){ float l = 100;//只需要计算反弹高度,经过的高度是其两倍 int i = 1; for (i = 1; i <= 10; i++) l /= 2; printf("10th:经过%.5f米,反弹%.5f米。\n", 2*l, l); return 0;}
3、编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒。如输入2004年12月31日23时59分59秒,则输出2005年1月1日0时0分0秒。
函数原型:PS:故意这么写的,别给乱换
void show_time(int *year, int *month, int *date, int *hour, int *minute, int *second)
#include <stdio.h>int is_leap_year(int year)//四年一闰,百年不闰, 四百年再闰{ if ((year % 400) == 0) return 1; else if ((year % 4 == 0) && (year % 100 != 0)) return 1; return 0;}int is_last_day(int year,int month,int day)//判断是不是该月的最后一天{ if (month == 2) { year = is_leap_year(year); if (year == 1) { if (day == 29) return 1; else return 0; } else { if (day == 28) return 1; else return 0; } } else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { if (day == 31) return 1; else return 0; } else if (day == 30) return 1; else return 0;}void show_time(int *year, int *month, int *date, int *hour, int *minute, int *second){ if ((*second + 1) == 60) { *second = 0; if ((*minute + 1) == 60) { *minute = 0; if ((*hour + 1) == 24) { *hour = 0; if (is_last_day(*year, *month, *date) == 1) { *date = 1; if (*month == 12) { *month = 1; *year += 1; } else *month += 1; } else *date += 1; } else *hour += 1; } else *minute += 1; } else *second += 1; printf("%d %d %d %d %d %d\n", *year, *month, *date, *hour, *minute, *second);}int main(void){ int year=0, month=0, date=0, hour=0, minute=0, second=0; printf("Input data:"); scanf("%d %d %d %d %d %d", &year, &month, &date, &hour, &minute, &second); show_time(&year, &month, &date, &hour, &minute, &second); return 0;}
阅读全文
0 0
- C语言练习题(10)
- C语言2014-11-10练习题
- C 语言练习题
- c语言循环练习题
- C语言程序练习题
- c语言练习题
- c语言练习题2
- c语言练习题1
- c语言练习题3
- c语言练习题
- c语言练习题
- c语言练习题
- c语言练习题
- c语言小练习题
- c语言练习题(二)
- C语言练习题 1
- C 语言练习题总结
- C语言练习题---strlen()
- junit+Activiti工作流完整源码
- 从最小支撑树和最短路径树学习图的优先级搜索
- 在数组后面添加指定元素
- js验证表单代码
- 大数运算模板
- C语言练习题(10)
- 机器学习sklearn库部署环境
- 一款时序数据库 MyData
- powerdesigner 把name生成注释
- 修改Linux SSH连接端口和禁用IP,安装DDoS deflate
- 梯度下降的算法笔记
- 二叉树的遍历
- Jackson将对象Object转换成json串时,如果对象中有成员变量为byte[]类型,则会将其转换成String
- 关于VB中的Trim函数浅析