Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <iostream> #include <stdlib.h> #define max_size 100 using namespace std; void tao_mang(int A[],int &n); void xuat_mang(int A[],int n); int gia_tri_lon_nhat(int A[],int n); int gia_tri_nho_nhat(int A[],int n); int tim_kiem(int A[],int n,int x); void them_phan_tu_vao_cuoi(int A[],int &n,int x); void chen(int A[],int &n,int vt,int gt); void xoa(int A[],int &n,int vt); void sap_xep(int A[],int n); int main() { int A[max_size],n; int tiep, gtln, gtnn; int vt,x; do { cout<<"\n\n\t vui long chon cac chuc nang sau: "; cout<<"\n\n1.tao day so"; cout<<"\n2.hien thi day so"; cout<<"\n3.tim max"; cout<<"\n4.tim min"; cout<<"\n5.tim phan tu x"; cout<<"\n6.bo sung phan tu"; cout<<"\n7.chen phan tu vao vi tri bat ki"; cout<<"\n8.xoa phan tu bat ki"; cout<<"9.sap xep day so"; cout<<"10.thoat"; int lua_chon; cout<<"\n\nlua chon chuc nang: "; cin>>lua_chon; while(lua_chon<1 || lua_chon >10) { cout<<"\n\t chon lai chuc nang: "; cin>>lua_chon; } switch(lua_chon) { case 1: //tao mang cout<<"\n\t nhap vao so luong phan tu: "; cin>>n; while(n<1 || n>max_size) { cout<<"\n\t nhap lai so luong phan tu: "; cin>>n; } tao_mang(A,n); break; case 2: cout<<"\n\n\t\t DAY SO CUA MANG LA"; xuat_mang(A,n); break; case 3: //gia tri lon nhat gtln=gia_tri_lon_nhat(A,n); cout<<"\n\n\t gia tri lon nhat cua mang la: "<<gtln; break; case 4: //gia tri nho nhat gtnn=gia_tri_nho_nhat(A,n); cout<<"\n\n\t gia tri nho nhat cua mang la: "<<gtnn; cout<<"\n\n-----------------------------------------"; break; case 5: //tim kiem cout<<"\n\nnhap vao so nguyen x can tim: "; cin>>x; while(x<0) { cout<<"\n\nnhap lai so nguyen x can tim: "; cin>>x; } vt=tim_kiem(A,n,x); if(vt!=-1) { cout<<"\n\tvi tri xuat hien la: "<<vt; } else { cout<<"\n\t khong co xuat hien trong mang"; } cout<<"\n\n-----------------------------------------"; break; case 6: //them phan tu vo cuoi int them; cout<<"\nnhap vao phan tu muon them o cuoi: "; cin>>them; while(them<0) { cout<<"\n\nnhap lai phan tu muon them o cuoi: "; cin>>them; } them_phan_tu_vao_cuoi(A,n,them); xuat_mang(A,n); cout<<"\n\n-----------------------------------------"; break; case 7: //chen vao vi tri bat ki int vt_chen,gt; cout<<"\n nhap vao vi tri can chen: "; cin>>vt_chen; while(vt_chen<=0 || vt_chen>n+1) { cout<<"\n\nnhap lai vi tri can chen: "; cin>>vt_chen; } cout<<"\n nhap vao gia tri can chen: "; cin>>gt; while(gt<0) { cout<<"\n\nnhap lai gia tri can chen: "; cin>>gt; } chen(A,n,vt_chen,gt); cout<<"\n\n\t mang sau khi chen la "; xuat_mang(A,n); cout<<"\n\n-----------------------------------------"; break; case 8: //xoa vi tri trong mang int vt_xoa; cout<<"\nnhap vao vi tri can xoa: "; cin>>vt_xoa; while(vt_xoa<=0 || vt_xoa>n) { cout<<"\n\nnhap lai vi tri can xoa: "; cin>>vt_xoa; } xoa(A,n,vt_xoa); xuat_mang(A,n); cout<<"\n\n-----------------------------------------"; break; case 9: //sap xep sap_xep(A,n); xuat_mang(A,n); cout<<"\n\n-----------------------------------------"; break; case 10: return 0; } cout<<"\n\nban muon tiep tuc khong: \n1.tiep\n2.khong"; cin>>tiep; } while(tiep==1); return 0; } void tao_mang(int A[],int &n) { for(int i=0; i<n; i++) { cout<<"\n nhap vao phan tu thu "<<i+1<<": "; cin>>A[i]; } } void xuat_mang(int A[],int n) { for(int i=0; i<n; i++) { cout<<"\nphan tu thu "<<i+1<<": "<<A[i]; } } int gia_tri_lon_nhat(int A[],int n) { int maxx=A[0]; for(int i=1; i<n; i++) { if(A[i]>maxx) { maxx=A[i]; } } return maxx; } int gia_tri_nho_nhat(int A[],int n) { int minn=A[0]; for(int i=1; i<n; i++) { if(A[i]<minn) { minn=A[i]; } } return minn; } int tim_kiem(int A[],int n,int x) { for(int i=0; i<n; i++) { if(A[i]==x) { return i+1; } } return -1; } void them_phan_tu_vao_cuoi(int A[],int &n,int x) { A[n]=x; n++; } void chen(int A[],int &n,int vt,int gt) { for(int i=n-1; i>=vt-1; i--) { A[i+1]=A[i]; } A[vt-1]=gt; n++; } void xoa(int A[],int &n,int vt) { for(int i=vt-1; i<=n-1; i++) { A[i]=A[i+1]; } n--; } void sap_xep(int A[],int n) { int tg; for(int i=0; i<n-1; i++) { for(int j=i+1; j<n; j++) { if(A[i]>A[j]) { tg=A[j]; A[j]=A[i]; A[i]=tg; } } } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत