0% found this document useful (0 votes)
56 views3 pages

#Include #Include #Include Void Int Int

The document defines functions for working with arrays in C++ including functions to: 1) Input and output arrays, calculate the sum and number of prime numbers in an array, check if an array is sorted in increasing order, swap two elements, sort an array in increasing order, remove an element from an array at a given position, find an element in an array, remove all occurrences of a given element from an array, and insert an element into an array at a given position. 2) It then demonstrates calling these functions by inputting an array, inserting an element, and outputting the modified array.

Uploaded by

NHULEE
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views3 pages

#Include #Include #Include Void Int Int

The document defines functions for working with arrays in C++ including functions to: 1) Input and output arrays, calculate the sum and number of prime numbers in an array, check if an array is sorted in increasing order, swap two elements, sort an array in increasing order, remove an element from an array at a given position, find an element in an array, remove all occurrences of a given element from an array, and insert an element into an array at a given position. 2) It then demonstrates calling these functions by inputting an array, inserting an element, and outputting the modified array.

Uploaded by

NHULEE
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream.h> #include<conio.h> #include<iomanip.

h> void nhapmang(int a[], int &n) { cout<<"Nhap vao so n: ";cin>>n; for (int i=0;i<n;i++) { cout<<"a["<<i<<"]: "; cin>>a[i]; } } void xuatmang(int a[], int n) { cout<<endl; for (int i=0;i<n;i++) cout<<a[i]<<" "; } int tinhtong(int a[], int n){ int tong=0; for(int i=0;i<n;i++) tong+=a[i]; return tong; } int ktsnt(int k){ if(k==1 || k==2) return 1; for(int i=2;i<(k/2)+1;i++) if(k % i==0) return 0; return 1; } int demsonguyento(int a[], int n){ int dem=0; for(int i=0;i<n;i++){ if(ktsnt(a[i])==1) dem++; } return dem; } int kttang(int a[], int n){ for(int i=0;i<n-1;i++) if(a[i]>a[i+1]) return 0; return 1; } void hoanvi(int &a, int &b) { int tmp=a; a=b;b=tmp; }

void sapxeptang(int a[], int n){ for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) if(a[i]>a[j]) hoanvi(a[i], a[j]); } void xoapt(int a[], int &n, int vitri){ for(int i=vitri;i<n-1;i++) a[i]=a[i+1]; n--; } int timx(int a[], int n, int k){ for(int i=0;i<n;i++) if(a[i]==k) return i; return -1; } void xoaconso(int a[], int &n, int k) { do{ int vitri=timx(a,n,k); if(vitri==-1) return; xoapt(a,n,vitri); }while(1); } void chenpt(int a[], int &n, int k, int vt) { n++; for(int i=n-1;i>vt;i--) a[i]=a[i-1]; a[vt]=k; }

void main(){ int x[100]; int spt; nhapmang(x,spt); cout<<"mang vua nhap:\n"; xuatmang(x,spt); int k, vt; cout<<"\nmuon chen pt nao vao vi tri nao: "; cin>>k>>vt; chenpt(x,spt,k,vt); cout<<"\nmang sau khi chen: "<<endl; xuatmang(x,spt);

You might also like