Bài Giải
/*
Name: Khao sat day so tang hay giam
Copyright: None
Author: Tran Anh
Description: http://www.code.tavn.net
*/
#include<conio.h>
#include<stdio.h>
main()
{
int n,i;
printf("\t- Nhap so phan tu cua mang: ");
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
printf("\t- Nhap phan tu A[%d]: ",i);
scanf("%d",&a[i]);
}
int tang=1,giam=1;
for (i=0;i<n-1;i++)
{
if (a[i]>a[i+1]) tang=0;
if (a[i]<a[i+1]) giam=0;
}
if (tang)
{
printf("\t=> Day so ban nhap TANG:\n\t");
for(i=0;i<n;i++)
printf("%5d",a[i]);
}
if (giam)
{
printf("\t=> Day so ban nhap GIAM:\n\t");
for(i=0;i<n;i++)
printf("%5d",a[i]);
}
if ((tang==0)&&(giam==0))
{
printf("\t=> Day so ban nhap BINH THUONG:\n\t");
for(i=0;i<n;i++)
printf("%5d",a[i]);
}
getch();
return 0;
}
Name: Khao sat day so tang hay giam
Copyright: None
Author: Tran Anh
Description: http://www.code.tavn.net
*/
#include<conio.h>
#include<stdio.h>
main()
{
int n,i;
printf("\t- Nhap so phan tu cua mang: ");
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
printf("\t- Nhap phan tu A[%d]: ",i);
scanf("%d",&a[i]);
}
int tang=1,giam=1;
for (i=0;i<n-1;i++)
{
if (a[i]>a[i+1]) tang=0;
if (a[i]<a[i+1]) giam=0;
}
if (tang)
{
printf("\t=> Day so ban nhap TANG:\n\t");
for(i=0;i<n;i++)
printf("%5d",a[i]);
}
if (giam)
{
printf("\t=> Day so ban nhap GIAM:\n\t");
for(i=0;i<n;i++)
printf("%5d",a[i]);
}
if ((tang==0)&&(giam==0))
{
printf("\t=> Day so ban nhap BINH THUONG:\n\t");
for(i=0;i<n;i++)
printf("%5d",a[i]);
}
getch();
return 0;
}