0% found this document useful (0 votes)
7 views2 pages

Cau 2

Uploaded by

anvabinh123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Cau 2

Uploaded by

anvabinh123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#pragma warning(disable:4996)

#include<stdlib.h>
#include<iostream>
#include<math.h>
using namespace std;
bool ktscp(int n){
if(sqrt(n)*sqrt(n)==n)return 1;
return 0;
}
int timmax(int* a,int n){
int max=a[0];
for(int i=0;i<n;i++){
if(a[i]>max) max=a[i];
}return max;
}
bool ktsnt(int n){
if(n<2)return 0;
for(int i=2;i*i<=n;i++){
if(n%i==0)return 0;
}
return 1;
}
void docfile(FILE *file,int* &a,int &n){
fscanf(file,"%d",&n);
for(int i=0;i<n;i++){
fscanf(file,"%d",&a[i]);
}
}
float trungbinh(int* a,int n){
int trungbinh=0;
int x=0;
for(int i=0;i<n;i++)
{
if(ktsnt(a[i]) ){
trungbinh+=a[i];
++x;
}
}
return (float)trungbinh/x;
}
void xoa(int a[], int &n, int snt)
{
if(snt>=0 && snt<n)
{
for(int i=snt;i<n-1;i++)
{a[i]=a[i+1];
n--;}
}
}
void cauc(FILE* file,int* a,int n){
for(int i=0;i<n;i++)
{
if( ktsnt(a[i]) ){
xoa(a,n,i);

}
}

}
void ghifile(FILE* file,int* a,int n){
fprintf(file,"%d\n",n);
for(int i=0;i<n;i++){
fprintf(file,"%d ",a[i]);
}
}
int caud(FILE* file,int* a,int n){
int min=timmax(a,n)+1;
while(!ktscp(min)){
min++;
}
return min;
}
int main(){
FILE *fi=fopen("input.txt","rt");
if(fi==NULL){
cout<<"ko mo dc file";
return 0;
}
int n,*a;
a=new int[n];
docfile(fi,a,n);

FILE *fo=fopen("output.txt","wt");
//ghifile(fo,a,n);
float tb=trungbinh(a,n);
fprintf(fo,"%f ",tb);
cauc(fi,a,n);
for(int i=0;i<n;i++){
fprintf(fo,"%d ",a[i]);
}
fprintf(fo,"%d ",caud(fi,a,n));
fclose(fi);
fclose(fo);
delete[] a;
return 0;
}

You might also like