LTCMang1
/* Lap trinh thuc hien nhap mang n so nguyen
+Sap xep tang dan va in ra (i,j,tg)
+Xoa cac so le va in ra (i,k)
+tinh tong cac so trong mang (i,tong) */
#include<stdio.h>
#include<conio.h>
int a[100],n,i,j,tg,tong,k;
void main()
{ clrscr();
printf("Nhap n:");scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("Nhap a[%d]:",i);
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j]);
{tg=a[i];
a[i]=a[j];
a[j]=tg;
}
printf("
Mang la:");
for(i=0;i<n;i++)
printf("%d ",a[i]);
for(k=i=0;i<n;i++)
if(a[i]%2==0)
{ a[k]=a[i];
k++;
}
n=k;
printf("
Mang vua xoa: ");
for(i=0;i<n;i++)
printf("%d",a[i]);
for(tong=i=0;i<n;i++)
tong=tong+a[i];
printf("
Tong la: %d",tong);
getch();
}
Bạn đang đọc truyện trên: Truyen247.Pro