This web page requires JavaScript to be enabled.

JavaScript is an object-oriented computer programming language commonly used to create interactive effects within web browsers.

How to enable JavaScript?

Xóa 1 phần tử, tách mảng thành 3 mảng con

10cth1-2 July 30, 2011 0

[codes=c]#include "conio.h"
#include "stdio.h"
#define MAX 100

void nhap_mang(int a[], int n)
{
  for(int i=0; i<n; i++)
  {
    printf("NHap a[%d]: ",i);
    scanf("%d", &a[i]);
  }
}

void xuat_mang(int a[], int n)
{
  for(int i=0; i<n; i++)
    {
      printf("%4d",a[i]);
    }
    printf("\n");
}

int xoa_gtri_x(int a[], int &n, int gt)
{
  int vt=-1;
  for(int i=0; i<n; i++)
    {
      if(a[i]==gt)      
        {
          vt=i;
          break;
        }
    }
  if(vt!=-1)
    {
      for(int j=vt; j<n;j++)
        {
          a[j]=a[j+1];
        }
        n–;
          return 1;
        
    }
  else
    return 0;
}

void tach_3_mang_con(int a[],int n, int b[], int &m, int c[], int &l, int d[], int &h)
{
  m=0;
  l=0;
  h=0;
  for(int i=0; i<n; i++)
    {
      if(a[i]>0)
        b[m++]=a[i];
      if(a[i]<0)
        c[l++]=a[i];
      if(a[i]==0)
        d[h++]=a[i];
    }
}

void main()
{
  int n, a[MAX],gt,x;
  int b[MAX], m, c[MAX], l, d[MAX], h;
  printf("Nhap vao so phan tu n: ");
  scanf("%d",&n);
    nhap_mang(a,n);
  printf("Mang vua nhap la: ");
    xuat_mang(a,n);
  printf("Nhap phan tu x: ");
  scanf("%d",&gt);
  int kq_xoa_gtri = xoa_gtri_x(a,n,gt);
    if(kq_xoa_gtri==0)
      printf("Xoa ko dc");
    else
      {
        printf("Xoa dc roi ne: ");
        xuat_mang(a,n);
      }
  tach_3_mang_con(a, n, b, m, c, l, d, h);
  xuat_mang(b,m);
  printf("\n");
  xuat_mang(c,l);
  printf("\n");
  xuat_mang(d,h);
//  printf("\n");
  getch();
}[/codes]


Last modified on March 31st, 2021 at 1:22 am

Nam Le
lequocnam



0 responds

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.