12.16

1、编写程序:读入一个在字母C和X之间的字符,打印出该字母在中间的相邻五个字母。
如:输入F,则输出DEFGH.
函数原型:void func(char ch)
思路:循环里向前-2,向后+2。

#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)
{
    int f;
    printf("请从键盘上输入字符:");
    scanf("%c",&f);

    func(f);
    return 0;
}

2、一个球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第十次反弹多高。
思路:打印高度和距离代码写的位置。高度减半,距离是高度的2倍。

#include<stdio.h>

int main(void)

{
    float h = 100;
    int i;
    for(i=1;i<10;i++)
    {
        h = h / 2;
    }
    printf("第十次反弹共经过%f米,反弹的高度为%f",2*h,h);
}

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)
思路:输入型参数,秒(59s)会进位。

#include<stdio.h>


猜你喜欢

转载自blog.csdn.net/linzetao233/article/details/78868777
今日推荐