Write a program with custom functions, how to customize functions

Updated on technology 2024-02-08
5 answers
  1. Anonymous users2024-02-05

    #include

    #define m 5

    #define n 4

    int sumstu(int a[n],int n) The total grade of each student.

    int sum=0,i;

    for(i=0;isum+=a[n][i];

    return sum;

    int sumsco(int a[n],int n) the overall grade for each course.

    int sum=0,i;

    for(i=0;isum+=a[i][n];

    return sum;

    void sort(int sum[m]) bubble sort.

    int i,j,t;

    for(i=0;ifor(j=0;jif(sum[j]t=sum[j];

    sum[j]=sum[j+1];

    sum[j+1]=t;

    void main()

    int i,a[m][n]=,sum1[m],sum2[n],sum3[m];

    for(i=0;isum1[i]=sum3[i]=sumstu(a,i);

    for(i=0;isum2[i]=sumsco(a,i);

    sort(sum3);

    printf("The overall score of each student:");

    for(i=0;iprintf("%d ",sum1[i]);

    printf("Overall grade for each course:");

    for(i=0;iprintf("%d ",sum2[i]);

    printf("The total score of each student is sorted from largest to smallest:");

    for(i=0;iprintf("%d ",sum3[i]);

    printf("");

  2. Anonymous users2024-02-04

    Steps to customize a function:

    1. Declare a custom function in the header file and define the function written by the user;

    2. Write down the implementation of the custom function in a C language file, which can be written before or after the main function;

    3. Call the custom header function in the main function, remember the declaration of the header file;

    4. Finally compile all the C files involved.

    Some custom functions may be called frequently, so it is not convenient to write them in a C file. These custom functions should be written in a C file and declared in a header file. The main function can be customized by referencing the header and then calling the desired custom function.

  3. Anonymous users2024-02-03

    For example, the average monthly food expenses are a (yuan), and after x (months) in a row, the total amount spent is y (yuan).

    Then y=ax, is a function, which is a custom function.

    Another example: y=2x+1, where x is limited to the closed interval [3,4].

    Also a custom function.

  4. Anonymous users2024-02-02

    Library functions are provided to you to facilitate program writing, and many of the library functions of C are written in assembly language to achieve relatively high running efficiency. Of course, programmers can also implement the functions of some library functions by themselves, but why should they repeat the existing things when writing ordinary programs? Don't think it's easy, the printf implementation alone is certainly not something you can write today.

    We basically reuse a lot of existing libraries to simplify the writing of programs.

    You don't know grammar yet, you can't use the language relatively well, and you can't talk about anything else.

  5. Anonymous users2024-02-01

    Why write your own ready-made functions when you have them? Others will have to check your mistakes when they see you.

Related questions