Daily practice of C language 7.25 (Class C high energy early warning)

Class A

1. (original) Mr. Geng has 10 students. Now the teacher is very angry. He wants to find out the student with the worst score to play PP. the following program realizes this function. The user is required to input 10 scores and output the lowest score and student number. The effect is as follows:

(Note: if more than one student has the lowest score, output the number of the first student)

Please add the following code to achieve this function:

#include <stdio.h>
int main() {
    int input, min, i, who;
    min = _________________;
    //Here: A. - 9999 b.0 c.9999
    printf("Please enter 10 scores:");
    for (i = 0; i < 10; i++) {
        scanf("%d", &input);
        if (input < min) {
            min = input;
            who = ___________________;
        }
    }
    printf("The students with the lowest score are:%d\n", who);
    printf("The minimum score is:%d\n", min);
    return 0;
}

Class B

2. (original) please write a program to output the full arrangement of 1, 2 and 3. The effect is as shown in the figure (Note: as long as you can output all the arrangements, the order may not be the same as the example)

Class C

3. (original) please write a program to ask the user to input n, and then output the full arrangement of 1 to N, the effect is as shown in the figure

 

-------------------------------Here is the answer------------------------------

 

 

 

 

 

 

 

 

 

 

1.

#include <stdio.h>
int main() {
    int input, min, i, who;
    min = 9999;
    printf("Please enter 10 scores:");
    for (i = 0; i < 10; i++) {
        scanf("%d", &input);
        if (input < min) {
            min = input;
            who = i + 1;
        }
    }
    printf("The students with the lowest score are:%d\n", who);
    printf("The minimum score is:%d\n", min);
    return 0;
}

2.

#include <stdio.h>
int main() {
    int a, b, c;
    for (a = 1; a <= 3; a++) {
        for (b = 1; b <= 3; b++) {
            for (c = 1; c <= 3; c++) {
                if (a != b && a != c && b != c) {
                    printf("%d %d %d\n", a, b, c);
                }
            }
        }
    }
    return 0;
}

3.

#include <stdio.h>
#include <stdlib.h>
void swap(int *x, int *y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}
void perm(int *a, int index, int length) {
    int i;
    if (index == length) {
        for (i = 0; i < length; i++) {
            printf("%d ", a[i]);
        }
        putchar('\n');
    } else {
        for (i = index; i < length; i++) {
            swap(&a[i], &a[index]);
            perm(a, index + 1, length);
            swap(&a[i], &a[index]);
        }
    }
}
int main() {
    int n, i, *a;
    printf("Please input n: ");
    scanf("%d", &n);
    a = (int *)malloc(sizeof(int) * n);
    for (i = 0; i < n; i++) {
        a[i] = i + 1;
    }
    perm(a, 0, n);
    return 0;
}

 

Added by Worqy on Fri, 31 Jan 2020 07:55:47 +0200