fork download
  1. // khai bao thu vien ham
  2. #include<math.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. // khai bao
  10. int a[100], n;
  11.  
  12. // 1- Nhập vào từ bàn phím dãy số nguyên dương có n số (3<n<100)
  13. cout<<"\n + Nhap so phan tu cua mang: ";
  14. do{
  15. cout<<"\n n= "; cin>>n;
  16. if(n<=3||n>=100)
  17. cout<<"\n Nhap lai n ! ";
  18. }while(n<=3||n>=100);
  19.  
  20. cout<<"\n Nhap mang: ";
  21. for(int i=0; i<n;i++)
  22. {
  23. do{
  24. cout<<"\n a["<<i<<"]= ";
  25. cin>>a[i];
  26. if(a[i]<0)
  27. cout<<"\n Nhap lai a["<<i<<"]!";
  28. }while(a[i]<0);
  29. }
  30.  
  31. // 2- In dãy số vừa nhập
  32. cout<<"\n + In day mang: ";
  33. int i=0;
  34. while(i<n){
  35. cout<<a[i]<<", ";
  36. i++;
  37. }
  38.  
  39. //3- Đếm số phần tử là số chẵn có trong dãy
  40. int demSoChan=0;
  41. i=0;
  42. while(i<n)
  43. {
  44. if(a[i]%2==0) demSoChan++;
  45. i++;
  46. }
  47. cout<<"\n + Dem so chan trong mang: "<<demSoChan;
  48.  
  49. // 4- Tính tổng các số > 5 trong dãy
  50. long tong=0;
  51. for(i=0;i<n;i++)
  52. if(a[i]>5)
  53. tong=tong+a[i];
  54. cout<<"\n + Tong cac so lon hon 5: "<< tong;
  55.  
  56. // 5- Tìm số lớn nhất có trong dãy
  57. int max=a[0];
  58. for(i=1;i<n;i++)
  59. if(max<a[i]) max=a[i];
  60.  
  61. cout<<"\n + Max = "<<max;
  62.  
  63. // 6- Đếm số phần tử là bội của 3 và 5 có trong dãy
  64. int demBoi3va5=0;
  65. for(i=0;i<n;i++)
  66. if(a[i]%3==0&&a[i]%5==0)
  67. demBoi3va5++;
  68. cout<<"\n + Dem boi cua 3 va 5: "<<demBoi3va5;
  69.  
  70. // 7- In ra tất cả số nguyên tố trong dãy
  71. cout<<"\n + In so nguyen to trong day: ";
  72.  
  73. for(i=0;i<n;i++)
  74. {
  75. int test=0;
  76. if(a[i]==1||a[i]==2||a[i]==3)
  77. cout<<a[i]<<", ";
  78. else
  79. {
  80. for(int j=2;j<a[i];j++)
  81. if(a[i]%j==0)
  82. {
  83. test=1;
  84. break;
  85. }
  86. if(test==0)
  87. cout<<a[i]<<", ";
  88. }
  89. }
  90.  
  91. cout<<"\n - END - \n";
  92. return 0;
  93. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:2: error: illegal character: '#'
#include<math.h>
^
Main.java:2: error: class, interface, or enum expected
#include<math.h>
        ^
Main.java:3: error: illegal character: '#'
#include <iostream>
^
Main.java:7: error: class, interface, or enum expected
int main()
^
Main.java:13: error: class, interface, or enum expected
    cout<<"\n + Nhap so phan tu cua mang: ";
    ^
Main.java:14: error: class, interface, or enum expected
    do{
    ^
Main.java:15: error: class, interface, or enum expected
        cout<<"\n n= "; cin>>n;
                        ^
Main.java:16: error: class, interface, or enum expected
        if(n<=3||n>=100)
        ^
Main.java:18: error: class, interface, or enum expected
    }while(n<=3||n>=100);
    ^
Main.java:20: error: class, interface, or enum expected
    cout<<"\n Nhap mang: ";
    ^
Main.java:21: error: class, interface, or enum expected
    for(int i=0; i<n;i++)
    ^
Main.java:21: error: class, interface, or enum expected
    for(int i=0; i<n;i++)
                 ^
Main.java:21: error: class, interface, or enum expected
    for(int i=0; i<n;i++)
                     ^
Main.java:25: error: class, interface, or enum expected
               cin>>a[i];
               ^
Main.java:26: error: class, interface, or enum expected
               if(a[i]<0)
               ^
Main.java:28: error: class, interface, or enum expected
           }while(a[i]<0);
           ^
Main.java:29: error: class, interface, or enum expected
       }
       ^
Main.java:33: error: class, interface, or enum expected
    int i=0;
    ^
Main.java:34: error: class, interface, or enum expected
    while(i<n){
    ^
Main.java:36: error: class, interface, or enum expected
        i++;
        ^
Main.java:37: error: class, interface, or enum expected
    }
    ^
Main.java:41: error: class, interface, or enum expected
    i=0;
    ^
Main.java:42: error: class, interface, or enum expected
    while(i<n)
    ^
Main.java:45: error: class, interface, or enum expected
        i++;
        ^
Main.java:46: error: class, interface, or enum expected
    }
    ^
Main.java:50: error: class, interface, or enum expected
    long tong=0;
    ^
Main.java:51: error: class, interface, or enum expected
    for(i=0;i<n;i++)
    ^
Main.java:51: error: class, interface, or enum expected
    for(i=0;i<n;i++)
            ^
Main.java:51: error: class, interface, or enum expected
    for(i=0;i<n;i++)
                ^
Main.java:54: error: class, interface, or enum expected
    cout<<"\n + Tong cac so lon hon 5: "<< tong;
    ^
Main.java:57: error: class, interface, or enum expected
    int max=a[0];
    ^
Main.java:58: error: class, interface, or enum expected
    for(i=1;i<n;i++)
    ^
Main.java:58: error: class, interface, or enum expected
    for(i=1;i<n;i++)
            ^
Main.java:58: error: class, interface, or enum expected
    for(i=1;i<n;i++)
                ^
Main.java:61: error: class, interface, or enum expected
    cout<<"\n + Max = "<<max;
    ^
Main.java:64: error: class, interface, or enum expected
    int demBoi3va5=0;
    ^
Main.java:65: error: class, interface, or enum expected
    for(i=0;i<n;i++)
    ^
Main.java:65: error: class, interface, or enum expected
    for(i=0;i<n;i++)
            ^
Main.java:65: error: class, interface, or enum expected
    for(i=0;i<n;i++)
                ^
Main.java:68: error: class, interface, or enum expected
    cout<<"\n + Dem boi cua 3 va 5: "<<demBoi3va5;
    ^
Main.java:71: error: class, interface, or enum expected
    cout<<"\n + In so nguyen to trong day: ";
    ^
Main.java:73: error: class, interface, or enum expected
    for(i=0;i<n;i++)
    ^
Main.java:73: error: class, interface, or enum expected
    for(i=0;i<n;i++)
            ^
Main.java:73: error: class, interface, or enum expected
    for(i=0;i<n;i++)
                ^
Main.java:76: error: class, interface, or enum expected
        if(a[i]==1||a[i]==2||a[i]==3)
        ^
Main.java:78: error: class, interface, or enum expected
        else
        ^
Main.java:80: error: class, interface, or enum expected
            for(int j=2;j<a[i];j++)
                        ^
Main.java:80: error: class, interface, or enum expected
            for(int j=2;j<a[i];j++)
                               ^
Main.java:84: error: class, interface, or enum expected
                    break;
                    ^
Main.java:85: error: class, interface, or enum expected
                }
                ^
Main.java:88: error: class, interface, or enum expected
        }
        ^
Main.java:92: error: class, interface, or enum expected
    return 0;
    ^
Main.java:93: error: class, interface, or enum expected
}
^
53 errors
stdout
Standard output is empty