Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Them vao gia tri x vao vi tri k
- // khai bao cac ham thu vien neu co
- #include<stdio.h>
- #include<conio.h>
- #define SIZE 100
- void nhap(int a[],int &n)
- {
- scanf("%d",&n);
- for(int i=0;i<n;i++)
- {
- scanf("%d",&a[i]);
- }
- }
- void xuat(int a[],int n)
- {
- for(int i=0;i<n;i++)
- {
- printf("%4d",a[i]);
- }
- }
- void them(int a[],int &n,int k,int x)
- {
- // k la vi tri can them
- //x la gia tri can them vao vi tri k
- for(int i=n;i>k;i--)
- {
- a[i]=a[i-1];
- }
- a[i]=x;
- n++;
- }
- void main()
- {
- int a[SIZE],n;
- nhap(a,n);
- int x,k;
- scanf("%d%d",&x,&k);
- them(a,n,k,x);
- xuat(a,n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement