Bài Giải
/*
Name: Dao nguoc mang mot chieu
Copyright: None
Author: Tran Anh
Description: http://www.code.tavn.net
*/
#include <conio.h>
#include <stdio.h>
main()
{
//Trang tri chuong trinh
int i;
printf("\t");
for (i=1;i<30;i++) printf("* ");
printf("\n\t\t CHUONG TRINH DAO NGUOC MOT MANG\n\n");
//Het doan chuong trinh trang tri
int n;
printf("\t- Nhap vao so phan tu: "); scanf("%d",&n);
int a[n];
printf("\n");
for (i=1;i<=n;i++)
{
printf("\t- Nhap vao phan tu a[%d]: ",i);
scanf("%d",&a[i]);
}
printf("\n\n");
printf("\t=> Mang ban da nhap: \n\t");
for (i=1;i<=n;i++)
printf("%d ",a[i]);
printf("\n\n");
printf("\t=> Mang sau khi dao chieu: \n\t");
int val;
for (i=1;i<=n/2;i++)
{
val=a[i];
a[i]=a[n-i+1];
a[n-i+1]=val;
}
for (i=1;i<=n;i++)
printf("%d ",a[i]);
getch();
return 0;
}
Name: Dao nguoc mang mot chieu
Copyright: None
Author: Tran Anh
Description: http://www.code.tavn.net
*/
#include <conio.h>
#include <stdio.h>
main()
{
//Trang tri chuong trinh
int i;
printf("\t");
for (i=1;i<30;i++) printf("* ");
printf("\n\t\t CHUONG TRINH DAO NGUOC MOT MANG\n\n");
//Het doan chuong trinh trang tri
int n;
printf("\t- Nhap vao so phan tu: "); scanf("%d",&n);
int a[n];
printf("\n");
for (i=1;i<=n;i++)
{
printf("\t- Nhap vao phan tu a[%d]: ",i);
scanf("%d",&a[i]);
}
printf("\n\n");
printf("\t=> Mang ban da nhap: \n\t");
for (i=1;i<=n;i++)
printf("%d ",a[i]);
printf("\n\n");
printf("\t=> Mang sau khi dao chieu: \n\t");
int val;
for (i=1;i<=n/2;i++)
{
val=a[i];
a[i]=a[n-i+1];
a[n-i+1]=val;
}
for (i=1;i<=n;i++)
printf("%d ",a[i]);
getch();
return 0;
}
Không có nhận xét nào:
Đăng nhận xét