fork download
  1. /*
  2. Bai tap: Nhap mang n phan tu so nguyen
  3. A. Tim gia tri Min, Max trong mang
  4. B. Tinh tong cac phan tu co gia tri chan trong mang
  5. C. Dem so luong cac so chinh phuong trong mang
  6. D. Liet ke cac so nguyen to trong mang theo thu tu giam dan
  7. */
  8. #include<oistream.h> # math.h
  9. void main(){
  10. int n,i,a[100]; // khai bao bien
  11. cout<< " nhap so luong phan tu= "; // tb nhap
  12. cin>> n' // nhap n
  13. for( i= 0; i< n; i ++){ // lap n lan
  14. cout << " a[ "<< i<<"]= ; // tb nhap a[i]
  15. cin >> a[i]; // nhap a[i]
  16. }
  17. int max = a[0]; // tam thoi coi a[0] la max
  18. for( i=1; i< n; i++) // duyet moi phan tu con lai
  19. if( a[i] > max) // net pt dang duyet > max
  20. max= a[i]; // cap nhat gia tri max moi
  21. cout<<" gia tri max = "<<max;
  22. (min) ="<<min<<" /n";
  23.  
  24. // dem so chan
  25. int dem = 0;// reset bien dem =0
  26. for( i=0; i<n; i++) // duyet moi phan tu
  27. If (a[i] %2 ==0) // neu phan tu dang duyet la chan
  28. dem ++; // thi tang bien dem len 1
  29. cout<<"/n so phan tu co gia tri chan ="<< dem<<";
  30. // liet ke cac so chinh phuong trong mang
  31. cout<<" cac so chinh phuong";
  32. for(i=0; i<n; i++)] // duyet moi phan tu
  33. int t=sqrt (a[i];
  34. if (a[i] <<" ";
  35. }
  36. //liet ke cac so nguyen to trong mang theo thu tu giam dan
  37. int NT[1000];
  38. int i,j,k,dem=0;
  39. for(i=0;i<n;i++)
  40. if(kt_nguyen_to(A[i])) dem++;
  41. if(dem==0) printf("\n Trong mang khong co so nguyen to \n");
  42. else // Neu co so nguyen to thi loc ra cac so ngto va sap xep
  43. { printf("\n D. Trong mang co %d so nguyen to \n",dem);
  44. i=0;k=0;
  45. while(i<n){
  46. if(kt_nguyen_to(A[i])) {NT[k]=A[i]; k++;}
  47. i++;
  48. }
  49. for(i=0;i<dem-1;i++)
  50. for(j=i+1;j<dem;j++)
  51. if(NT[i]<NT[j]){
  52. k=NT[i];
  53. NT[i]=NT[j];
  54. NT[j]=k;
  55. }
  56. // Hien thi ket qua ra man hinh
  57. printf("\n Danh sach cac so nguyen to theo thu tu giam dan \n");
  58. for(i=0;i<dem;i++) printf("%6d",NT[i]);
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:8:22: warning: extra tokens at end of #include directive [enabled by default]
 #include<oistream.h> # math.h
                      ^
prog.cpp:8:30: fatal error: oistream.h: No such file or directory
 #include<oistream.h> # math.h
                              ^
compilation terminated.
stdout
Standard output is empty