Solve several C language problems, and ask you to write sentences and attach the meaning of each sen

Updated on technology 2024-02-11
4 answers
  1. Anonymous users2024-02-06

    I want to write it to you! It's a pity that I'm off work, hehe.

  2. Anonymous users2024-02-05

    1.Here's an algorithm that uses branching statements to calculate how many days a day is the first day of the year:

    int year, month, day;

    Read into the year, month, and day.

    cin >>year >>month >>day;

    Calculate the number of days per month.

    int days_in_month[12] = ;

    If it is a leap year, February has 29 days.

    if (is_leap_year(year))

    days_in_month[1] = 29;

    The calculation date is the first day of the year.

    int day_of_year = day;

    for (int i = 0; i < month - 1; i++)

    day_of_year += days_in_month[i];

    cout The above algorithm uses an array of days in month to store the number of days in each month and adjust the number of days in February depending on whether it is a leap year. Then, by going through all the months and adding up the number of days in all the months, you can get the date being the first day of the year.

    Note: The above algorithm assumes that the months are numbered from 1, if the months are numbered from 0, you need to change the month - 1 in the above algorithm to month.

    It's important to note that the is leap year function in the algorithm above isn't given, as the implementation method depends on the language you're using. In C++, you can use the following ** to determine if a year is a leap year:

    bool is_leap_year(int year) {

    if (year % 4 != 0) {

    return false;

    else if (year % 100 != 0) {

    return true;

    else if (year % 400 != 0) {

    return false;

    To determine if a number is a "daffodil number", the following algorithm can be used:

    Convert numbers to strings.

    Convert the string to an array, using the sum of the cubes of each number to calculate the result.

    If the result of the calculation is equal to the original number, the number is "Daffodil Number", otherwise it is not.

    For example, here's an example implementation of python:

    def is_narcissistic(num):

    num_str = str(num)

    result = 0

    for digit in num_str:

    result += int(digit) *3

    return result == num

    When using the function, simply call is narcissistic(153) and it will return true.

  3. Anonymous users2024-02-04

    import ;

    public class demo01 1 else defines the number of days per month for an array to be stored.

    int s = ; int days = day;Storage This is the first day of the year for (int i = 0; i < month - 1; i++)"This day is" + year + "The first of the year" + days + "days");

    public class demo01 1 else defines the number of days per month that an array is stored int s = ; int days = day;Storage This is the first day of the year for (int i = 0; i < month - 1; i++)"This day is" + year + "The first of the year" + days + "days");

  4. Anonymous users2024-02-03

    The first question, from the title, from the title, enter an array of characters into the item, and pass the item to delnum for processing, the loop in delnum is to judge whether s[i] is less than one by one'0'Or greater than 9, that is, to determine whether s[i] is non-digital, if it is not a number, then use s[j++]=s[i] to save the content, for example, for example, enter a9, in delnum, the first cycle i=0, s[0] is'a', if the condition is satisfied, so s[0]='a', j from 1 to 1, i from 1 to 1

    The second cycle is i=1 and s[1] is'9', not satisfying if, so j is still 1, and i becomes 2 since adding 1

    From this process, it can be seen that the missing blank is actually the end position of the s array, because j is actually the last position of a valid letter, so the empty space is directly filled in s[j]='\0';That's it.

    Question 2: In the for loop, the length at the beginning of each time is set to 0, and the while loop is used to determine whether the current position of p is a space or. , obviously, if p the current position is not a space or.

    Then the current word length should be increased by 1, so that empty is length++;

Related questions
16 answers2024-02-11

Definition of a for loop.

for(the initial value of the variable; termination of operating conditions; The initial value of the first cycle i is 0, and it runs until i=3 stops i=2, and the condition is still satisfied, and the loop body is still executed, and the step size is 1+1 each time >>>More

4 answers2024-02-11

2. 1, True 2, False (there is only one program) 3, False (not necessarily) 4, True. >>>More

10 answers2024-02-11

main() [main function main program].

int i,j,k;【Define integer data i,j,k】for(i=1; i<=6;i++) main loop, i from 1 to 6, increasing to 1] for(j=1; j<=20-2*i;j++) subcycle, j from 1 to 20-2*i >>>More

12 answers2024-02-11

This problem requires understanding that the system allocates memory to static variables when compiling, and the memory units occupied by them are not released after the function call ends, that is, the value of the variable is the value of the previous function call at the next function call. >>>More

9 answers2024-02-11

It should be 0It should be a remainder operation.