C helped me go through 2 very simple things

Updated on technology 2024-04-12
6 answers
  1. Anonymous users2024-02-07

    First question:

    Write a simple recursive function to do this:

    int sum(int n)

    if(n==1)

    return 1;

    elsereturn n+sum(n-1);

    The argument n of the function can be given by itself.

    Second question:

    First of all, you have to determine whether the number is prime.

    Judgment method: divide the number by the number that is smaller than its own square but greater than 1.

    Then add them up.

  2. Anonymous users2024-02-06

    #include

    int sum1(int n) recursively finds 1+2+...nif(n==0)return 0;

    return n+sum1(n-1);

    bool prime(int n) determines whether it is prime.

    if(n<=1)return false;

    for(int i=2;iif(!(n%i))return false;

    return true;

    int sum2() finds the sum of prime numbers from 3 to 1000.

    int sum=0;

    for(int i=3;i<=1000;i++)if(prime(i))sum+=i;

    return sum;

    void main()

    int n;printf("Enter the requirements and n");

    scanf("%d",&n);

    int k=sum1(n);

    printf("The sum sought is: %d",k);

    k=sum2();

    printf("The sum of primes from 3 to 1000 is: %d",k);

  3. Anonymous users2024-02-05

    1 Use the recursive method to find 1+2+3+4+5+...The value of n (n<100) is main().

    int i;

    int sum=0;

    for (i=1;i<100;i++)

    sum=sum+i;

    printf("%d",sum);

    2 Find the sum of all prime numbers between 3-1000.

    main()

    int i,j;

    int sum=0;

    for (i=3;i<=6;i++)

    for (j=2;j=i)

    sum=sum+i;

    printf("%5d",sum);

  4. Anonymous users2024-02-04

    0x a .1 f p10 i.e. 10 + 1 * (16 to the power of -1) + 15 * (16 to the power of -2 to the power of 2).

    1*(16 to the power of -1) + 15* (to the power of 16 to the power of -2) How did it come about?

    You just think about the decimal system:

    1 + 2 * (10 to the power of -1) + 3 * (10 to the power of -2) so the same principle as the base hexadecimal.

  5. Anonymous users2024-02-03

    1. Question 10 is b

    The members of the union are stored from the same address. The size of the common body is generally calculated by the length of the member with the largest actual space occupation (here is the maximum size of int b[3]: 3*4=12). If the length of the member is not an integer multiple of the length of other member types (or the length of the array type if it is an array), it is expanded to an integer multiple that satisfies the size of the member.

    The other two arrays here are char and long, the size is 1 and 4, and 12 is exactly their integer multiple, so you don't need to expand it.

    2. Question 7 is selected D

    The address of the first member of the struct is the same as the address of the first member of the struct, and the offset of each member address from the address of the first address of the struct is an integer multiple of the size of the member. The total size of the construct must be an integer multiple of the largest of its members, and padding bytes must be added at the end if not.

    According to the above method of calculating the union size, the union uu size is 8. So the first int r1 is of size 4 and the offset is 4; The second double r2 is of size 8 and the offset is 0; The third float r3 is of size 4, the offset is 4, and the union uu size is 8, so the total size is (4+4)+8+(4+4)+8=32.

    Let's take a look.

  6. Anonymous users2024-02-02

    The question you asked first starts with breaking down the problem:

    1. Function 1 implements a binary method to find a character in an array of characters.

    2. Function 2 uses a dichotomy to find a string (word) in an array of strings (each string is an English word).

    3. Function 3 realizes the sorting of word arrays (the dichotomy is the search for ordered arrays, which must be sorted first).

    4. Function 4 recognizes and disassembles any string, disassembles all English words in it, and stores the array (the size of the array is still uncertain, and dynamic array implementation or linked list is required).

    5. The dichotomy also needs to be written in two ways: ordinary functions and recursion.

    6. The input line of strings, no format restrictions, no content restrictions, what is the basis for word recognition, such as containing other characters:"book@*shop"You are splitting it into two words, or a word.

    With that in mind, how do you want to simplify the statement?

Related questions
9 answers2024-04-12

You can use the mkdir() function to create a new folder and modify it on the basis of the original program as follows: >>>More

9 answers2024-04-12

The original meaning of the question is to implement the function of one queue with two stacks. >>>More

8 answers2024-04-12

n!is the factorial of n, and its mathematical meaning is n!=1*2*3*4*..The NC language implementation is as follows: (the program is debugged in the Turboc environment) int factorial(int n). >>>More