#include<stdio.h>// chi can input output thoi#include<limits.h>intgetInt(int min,int max,char msg[],char err[]){int num;int check;char c;do{printf("%s",msg);
check =scanf("%d%c",&num,&c);if(check!=2||c!='\n'|| num<min||num>max){
check =0;fflush(stdin);//fpurge(stdin)printf("%s",err);}}while(check==0);return num;}intmain(){int n;// size cua mangwhile(1){printf("Dynamic memory allocation\n");
n=getInt(1, INT_MAX,"\n\tNumber of element s= ","Ban can nhap 1 so nguyen duong.");int a[n];// thuong la a[100] nhung de ko phu hojp vif co the thua hay thieu nen dung a[n]int sum=0;for(int i=0; i<n; i++){
a[i]=getInt(INT_MIN, INT_MAX,"\tEnter an integr: ","Ban can nhap 1 so nguyen duong.\n");
sum+=a[i];}printf("\tSum = %d ", sum);printf("\nPress any key to continue. ");char c;fflush(stdin);scanf("%c",&c);}return0;}