Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
926 B
2
Indexable
Never
#include <stdio.h>

int main() {
    int n;
    printf("Nhap so luong phan tu:");
    scanf( "%d", &n );
    
    int arr[n];
    
    for(int i = 0; i < n; ++i) {
        printf("Nhap phan tu thu %d: ", i + 1);
        scanf("%d", &arr[i]);
    }
    
    // In ra phan tu vua nhap
    for(int i = 0; i < n; ++i) {
        printf("%d ", arr[i] );
    }
    
    int max = arr[0];
    for(int i = 0; i < n; ++i ) {
        if( max <= arr[i] ) {
            max = arr[i];
        }
    }
     printf("\nPhan tu co gia ti lon nhat: %d ", max );
    
    int sum = 0;
    for(int i = 0; i < n; ++i) {
        sum+= arr[i];
    }
    
    printf("\nTong cua cac phan tu: %d ", sum );
    
    printf("\nTrung binh cong cua cac phan tu: %.2lf ", (float) sum / n);
    
    printf("\nCac so chan: ");
    for(int i = 0; i < n; ++i) {
        if(arr[i] % 2 == 0) {
            printf("%d, ", arr[i]);
        }
    }

    return 0;
}
Leave a Comment