Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
1.2 kB
2
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
void nhapGiaTriMang(int* a, int* n){

    printf("nhap n ");
    scanf("%d", n);

    for(int i = 0; i < *n; ++i) {
        printf("nhap a[%d] ", i);
        scanf("%d", a + i);
    }

}
float tinhGiaTriTrungBinh(int* a, int n){

    float s = 0;

    for(int i = 0; i < n; ++i)
        s += a[i];

    s /= (float)n;
    return s;
}
int timMinIndex(int* a, int n){

    int m = a[0];
    int t = 0;

    for(int i = 1; i < n; ++i)
        if(a[i] < m) {
            m = a[i];
            t = i;
        }

    return t;
}
void sapXep(int* a, int n){

    for(int i = 1; i < n; ++i)
        for(int j = 0; j < i; ++j)
            if(a[j] > a[i]) {
                int t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
}



int main()
{

    int a[9999];
    int n = 0;

    nhapGiaTriMang(a, &n);
    float tb = tinhGiaTriTrungBinh(a, n);
    printf("gia tri trung binh %f \n", tb);
    int ti = timMinIndex(a, n);
    printf("min index %d \n", ti);

    sapXep(a, n);
    for(int i = 0; i < n; ++i) {
        printf("a[%d] %d\n", i, *(a + i));
    }

    return 0;
}
Leave a Comment