12.16

1. Write a program: read a character between the letters C and X, and print out the five adjacent letters in the middle of the letter.
Such as: input F, then output DEFGH.
Function prototype: void func (char ch)
Ideas: forward -2 in the loop, +2 backward.

#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. A ball falls freely from a height of 100 meters, and bounces back to half of its original height each time it hits the ground; how many meters does it travel when it hits the 10th time? How high is the tenth rally.
Idea: Print the height and distance where the code is written. The height is halved, and the distance is 2 times the height.

#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. Write a function that requires inputting the year, month, day, hour, minute, and second, and outputs the next second of the year, month, day, hour, minute, and second. If the input is 23:59:59 on December 31, 2004, the output will be 0:0:0:00 on January 1, 2005.
Function prototype: PS: It is written like this on purpose, don't change it
randomly. void show_time(int *year, int *month, int *date, int *hour, int *minute, int *second)
Ideas: input parameters, seconds (59s ) will carry over.

#include<stdio.h>


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325920120&siteId=291194637