Custom Function Practice ~ Student Information Management Program __ function

Source: Internet
Author: User
Tags function definition

Practiced a small program of student information relationships:
The functions involved are:
1: Entry Score
2: The ranking of the results
3: Print out the results
4: Find a certain score

Sort the key points: bubble sort, outer loop each time is the number of cycles minus 1
The inner loop is the internal cycle minus the number of outer loops minus 1, the principle can be reviewed before the blog

Find key points: Locate the subscript for an array element and return it to an index

The benefit of a custom function is that the main function calls the print function, which is handy for code reuse

The writing of three elements of function

How to measure the size of an array element, the total memory of the array divided by the size of the first element of the array

#include <stdio.h> #include <stdlib.h> #define N 5//1: Input//2: Sort//3: Print the address of the array to the function in some format.
void input (double[]);//input function void sort (double[]);


void Show (double[]);//function definition//To find NUM in the array passed in, if present, return subscript, does not exist, return-1 int find (Double*,int findnum); int main () {//volume array size double test[]={1,2,3,4,5,6,4} printf (number of elements of test array:%d\n, sizeof (test)/sizeof (test[0));/measure array element
  The number of double scores[n];
   Double findnum;//the number//1 to find. Input input (scores);
   printf ("Before: \ n");
   Show (scores);
   2: Sorted sort (scores);
   3: Sort after printf ("sorted: \ n");


   Show (scores);
   printf ("Please enter the number you want to find:");
   scanf ("%lf", &findnum);
   printf ("Look for the number subscript:%d\n", find (Scores,findnum));
return 0;
   int find (double *scores,int findnum) {int findindex=-1;//subscript int i to look for;
           for (i=0;i<n;i++) {if (Findnum==scores[i])//if (findnum=* (scores+i) {//record subscript to find, end find action
           Findindex=i;
       Break
} return findindex; } void input (double sCores[]) {int i;
        for (i=0;i<n;i++) {printf ("Enter page%d results:", i+1);
        scanf ("%lf", &scores[i]);
    scanf ("%lf", (Scores+i));

} void Show (double scores[]) {int i; printf ("***************************\n");
printf ("Chinese \ t math \ t english \ t-physics \ n");
for (i=0;i<n;i++) {printf ("%.2lf\t", * (Scores+i)),//scores[i]} printf ("***************************\n");
     } void sort (double scores[]) {int i,j;
     Double temp;
              for (i=0;i<n-1;i++) {for (j=0;j<n-i-1;j++) if (scores[j]>scores[j+1]) {
                temp = Scores[j];
                SCORES[J] = scores[j + 1];
         Scores[j + 1] = temp;







 }
     }
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.