// khai bao thu vien ham
#include<math.h>
#include <iostream>
using namespace std;
int main()
{
// khai bao
int a[100], n;
// 1- Nhập vào từ bàn phím dãy số nguyên dương có n số (3<n<100)
cout<<"\n + Nhap so phan tu cua mang: ";
do{
cout<<"\n n= "; cin>>n;
if(n<=3||n>=100)
cout<<"\n Nhap lai n ! ";
}while(n<=3||n>=100);
cout<<"\n Nhap mang: ";
for(int i=0; i<n;i++)
{
do{
cout<<"\n a["<<i<<"]= ";
cin>>a[i];
if(a[i]<0)
cout<<"\n Nhap lai a["<<i<<"]!";
}while(a[i]<0);
}
// 2- In dãy số vừa nhập
cout<<"\n + In day mang: ";
int i=0;
while(i<n){
cout<<a[i]<<", ";
i++;
}
//3- Đếm số phần tử là số chẵn có trong dãy
int demSoChan=0;
i=0;
while(i<n)
{
if(a[i]%2==0) demSoChan++;
i++;
}
cout<<"\n + Dem so chan trong mang: "<<demSoChan;
// 4- Tính tổng các số > 5 trong dãy
long tong=0;
for(i=0;i<n;i++)
if(a[i]>5)
tong=tong+a[i];
cout<<"\n + Tong cac so lon hon 5: "<< tong;
// 5- Tìm số lớn nhất có trong dãy
int max=a[0];
for(i=1;i<n;i++)
if(max<a[i]) max=a[i];
cout<<"\n + Max = "<<max;
// 6- Đếm số phần tử là bội của 3 và 5 có trong dãy
int demBoi3va5=0;
for(i=0;i<n;i++)
if(a[i]%3==0&&a[i]%5==0)
demBoi3va5++;
cout<<"\n + Dem boi cua 3 va 5: "<<demBoi3va5;
// 7- In ra tất cả số nguyên tố trong dãy
cout<<"\n + In so nguyen to trong day: ";
for(i=0;i<n;i++)
{
int test=0;
if(a[i]==1||a[i]==2||a[i]==3)
cout<<a[i]<<", ";
else
{
for(int j=2;j<a[i];j++)
if(a[i]%j==0)
{
test=1;
break;
}
if(test==0)
cout<<a[i]<<", ";
}
}
cout<<"\n - END - \n";
return 0;
}
Ly8ga2hhaSBiYW8gdGh1IHZpZW4gaGFtCiNpbmNsdWRlPG1hdGguaD4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkKewogICAgLy8ga2hhaSBiYW8KICAgIGludCBhWzEwMF0sIG47CiAgICAKICAgIC8vIDEtIE5o4bqtcCB2w6BvIHThu6sgYsOgbiBwaMOtbSBkw6N5IHPhu5Egbmd1ecOqbiBkxrDGoW5nIGPDsyBuIHPhu5EgKDM8bjwxMDApCiAgICBjb3V0PDwiXG4gKyBOaGFwIHNvIHBoYW4gdHUgY3VhIG1hbmc6ICI7CiAgICBkb3sKICAgICAgICBjb3V0PDwiXG4gbj0gIjsgY2luPj5uOwogICAgICAgIGlmKG48PTN8fG4+PTEwMCkKICAgICAgICAgICAgY291dDw8IlxuIE5oYXAgbGFpIG4gISAiOwogICAgfXdoaWxlKG48PTN8fG4+PTEwMCk7CiAgICAKICAgIGNvdXQ8PCJcbiBOaGFwIG1hbmc6ICI7CiAgICBmb3IoaW50IGk9MDsgaTxuO2krKykKICAgICAgIHsKICAgICAgICAgICBkb3sKICAgICAgICAgICAgICAgY291dDw8IlxuIGFbIjw8aTw8Il09ICI7CiAgICAgICAgICAgICAgIGNpbj4+YVtpXTsKICAgICAgICAgICAgICAgaWYoYVtpXTwwKQogICAgICAgICAgICAgICAgICAgY291dDw8IlxuIE5oYXAgbGFpIGFbIjw8aTw8Il0hIjsKICAgICAgICAgICB9d2hpbGUoYVtpXTwwKTsKICAgICAgIH0KICAgIAogICAgLy8gMi0gSW4gZMOjeSBz4buRIHbhu6thIG5o4bqtcAogICAgY291dDw8IlxuICsgSW4gZGF5IG1hbmc6ICI7CiAgICBpbnQgaT0wOwogICAgd2hpbGUoaTxuKXsKICAgICAgICBjb3V0PDxhW2ldPDwiLCAiOwogICAgICAgIGkrKzsKICAgIH0KICAgIAogICAgLy8zLSDEkOG6v20gc+G7kSBwaOG6p24gdOG7rSBsw6Agc+G7kSBjaOG6tW4gY8OzIHRyb25nIGTDo3kKICAgIGludCBkZW1Tb0NoYW49MDsKIC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2k8bjtpKyspCiAgICB7CiAgICAgICAgaW50IHRlc3Q9MDsKICAgICAgICBpZihhW2ldPT0xfHxhW2ldPT0yfHxhW2ldPT0zKQogICAgICAgICAgICBjb3V0PDxhW2ldPDwiLCAiOwogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGZvcihpbnQgaj0yO2o8YVtpXTtqKyspCiAgICAgICAgICAgICAgICBpZihhW2ldJWo9PTApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgdGVzdD0xOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICBpZih0ZXN0PT0wKQogICAgICAgICAgICAgICAgY291dDw8YVtpXTw8IiwgIjsKICAgICAgICB9CiAgICB9CiAgICAKICAgIGNvdXQ8PCJcbiAtIEVORCAtICBcbiI7CiAgICByZXR1cm4gMDsKfQ==
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