baitap42
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
float mang[5];
int i,j,dem,k,h;
main()
{
float tong,min,sapxep;
//nhap so vao mang
for (i=0;i<5;i++)
{
printf("mang[%d]= ",i);
scanf("%f",&mang[i]);
}
//tong cac phan tu cua mang
for (i=0;i<5;i++)
{
tong=tong+mang[i];
}
printf ("tong cac phan tu cua day la %2.1f",tong);
//tim so duong min neu co
for (i=0;i<5;i++)
if (mang[i]>0)
{
min=mang[i];
k++;
break;
}
for (i=0;i<5;i++)
{
if ((mang[i]>0)&&(mang[i]<min)) min=mang[i];
}
if (k!=0) printf("
so duong be nhat la %2.1f",min);
else puts("
khong co so duong nao");
// dem xem co bao nhieu so am
for(i=0;i<5;i++)
{
if(mang[i]<0) dem++;
}
printf("
co %d so am ",dem);
//xet xem co it nhat 2 so am dung canh nhau
for (i=0;i<4;i++)
if ((mang[i]<0)&&(mang[i++]<0)) h++;
printf("
co %d vi tri so am dung canh nhau ",h);
//sap day theo chieu tang dan
for (i=0;i<4;i++)
for (j=i+1;j<5;j++)
if (mang[j]<mang[i])
{
sapxep=mang[j];
mang[j]=mang[i];
mang[i]=sapxep;
}
puts("
day da sap xep theo chieu tang dan ");
for (i=0;i<5;i++)
printf(" %2.1f ",mang[i]);
getch();
}
/******************************************HOC TOT MON LAP TRINH C NHE!***************************************************/
Bạn đang đọc truyện trên: AzTruyen.Top