By GokiSoft.com|
20:10 20/09/2023|
Lập Trình C
Bài tập ôn luyện mảng 1 chiều - Lập trình C
Bài 1 : Nhập vào mảng gồm N số nguyên - In ra danh sách ngược của mảng đó
Ví du : mảng nhập vào là : 1, 2, 3, 4, 5, 6 -> In ra kết quả như sau : 6, 5, 4, 3, 2, 1
Bài 2 : Nhập vào mảng gồm N số nguyện -> Thực hiện hoán đổi ngược lại vị tri của mang
ví du : mảng a gồm các phần tử 1, 2, 3, 4, 5, 6 -> yêu cầu chuyển đổi để mảng a chưa danh sách ngược : 6, 5, 4, 3, 2, 1
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Đỗ Mạc Nam [T2008A]](https://www.gravatar.com/avatar/1935afd10c12c817a4c2882828a07d83.jpg?s=80&d=mm&r=g)
Đỗ Mạc Nam
2020-09-18 04:39:38
Bai 1
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argc[])
{
int i, n;
printf("\nNhap n: ");
scanf("%d", &n);
int A[n];
int i;
for(i=1;i<=n;i++) {
printf("\nNhap A[n]: ");
scanf("%d",&A[i]);
}
for(i=n;i>0;i--) {
printf("\nDanh sach nguoc cua A: %d", i);
}
return 0;
}
![Bùi Văn Mạnh [T2008A]](https://www.gravatar.com/avatar/17e9c94870c94e61c9203ee31dccf01c.jpg?s=80&d=mm&r=g)
Bùi Văn Mạnh
2020-09-18 04:17:16
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, n;
printf("\nNhap so nguyen N: ");
scanf("%d", &n);
int k[n];
for(i=0; i<=n-1; i++){
printf("\nNhap k[%d]",i);
scanf("%d", &k[i]);
}
for(i=n-1; i>=0; i--){
printf("\n%d", k[i]);
}
return 0;
}
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2020-09-17 15:25:40
bài 1
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n;
printf("\nnhap so phan tu cua mang: "); scanf("%d",&n);
int A[n];
int i;
for(i=1;i<=n;i++){
printf("\nnhap A[n]: "); scanf("%d",&A[i]);
}
for(i=n;i>0;i--) {
printf("\ndanh sach nguoc cua A: %d",i);
}
return 0;
}
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2020-09-17 13:10:12
bai 2
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai 2
int main(int argc, char *argv[]) {
int i,n,t;
i=0;
printf("\nhap n la: ");
scanf("%d",&n);
int c[n];
for(i=0;i<n;i++){
printf("\n nhap phan tu c[%d] = ",i);
scanf("%d", &c[i]);
}
printf("\nnguoc lai : ");
for(t=0,i=n-1;i>=0,t<n;t++,i--){
printf("\nc[%d] = %d",c[i],c[t]);}
return 0;
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2020-09-17 08:54:27
//BAI 2
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i,n;
printf("Nhap so phan tu trong mang n: ");
scanf("%d", &n);
int k[n];
if(n<=0){
printf("Nhap sai gia tri n");
} else{
i = 0;
while(i<n){
printf("Nhap tra tri cho phan tu cua mang k[%d]: ", i);
scanf("%d", &k[i]);
i++;
}
int b;
printf("\n Ban co muon dao nguoc mang khong \n1.Co \n2. Khong");
printf("\nChoose =: ");
scanf("%d", &b);
switch(b){
case 1:
i = n - 1;
while(i>=0){
printf("\nGia tri Mang nguoc la: %d", k[i]);
i--;
}
break;
case 2:
printf("Khong co gi thay doi");
break;
}
}
return 0;
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2020-09-17 07:44:50
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
// bai 2
int main(int argc, char *argv[]) {
int n;
printf("\nNhap n: ");
scanf("%d", &n);
if(n<=0){
printf("\nSai");
}else{
int a[n], i;
while(i<n){
printf("\nNhap a[%d]", i);
scanf("%d", &a[i]);
i++;
}
int b;
printf("\nBan co muon dao nguoc vi tri cua mang khong.");
printf("\nChon 1 de co");
printf("\nChon 2 de exit");
printf("\nChon: "); scanf("%d", &b);
if(b==1){
i=n-1;
while(i<n && i>=0){
printf("\n%d", a[i]);
i--;
}
}
if(b==2){
printf("\nexit");
}
}
return 0;
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2020-09-17 07:23:40
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
// bai 1
int main(int argc, char *argv[]) {
int i, n;
printf("\nNhap so nguyen N: ");
scanf("%d", &n);
int t[n];
for(i=0; i<=n-1; i++){
printf("\nNhap t[%d]", i);
scanf("%d", &t[i]);
}
for(i=n-1; i>=0; i--){
printf("\n%d", t[i]);
}
return 0;
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2020-09-17 04:50:23
#include<stdio.h>
int main(){
int n;
printf("\nNhap n: ");
scanf("%d",&n);
if(n<=0){
printf("\nSai index");
}
else{
int a[n],i=0;
while(i<n){
printf("Nhap a[%d] = ",i);
scanf("%d",&a[i]);
i++;
}
int b;
printf("\nBan co muon chuyen doi ve mang dao nguoc khong?\n1.Co\n2.Khong\n");
printf("Chon: ");
scanf("%d",&b);
if(b==1){
i=n-1;
while(i<n && i>=0){
printf("%d ",a[i]);
i--;
}
}
if(b==2){
printf("Ok the thoi bien di");
}
}
return 0;
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2020-09-17 04:40:52
#include<stdio.h>
int main(){
int n;
printf("\nNhap n: ");
scanf("%d",&n);
if(n<=0){
printf("\nSai index");
}
else{
int a[n],i=0;
while(i<n){
printf("Nhap a[%d] = ",i);
scanf("%d",&a[i]);
i++;
}
i=n-1;
while(i<n && i>=0){
printf("%d ",a[i]);
i--;
}
}
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2020-09-17 03:58:03
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i,N, k[N];
printf("Nhap so phan tu trong mang N =");
scanf("%d", &N);
for(i=0;i<=N-1;i++){
printf("Nhap gia tri phan tu trong mang k[%d] =", i);
scanf("%d", &k[i]);
}
for(i=0;i<=N-1;i++){
printf("\nCac phan tu trong mang nhu sau: %d", k[i]);
}
for(i=N-1;i>=0;i--){
printf("\nCac phan tu trong mang in nguoc lai nhu sau: %d", k[i]);
}
return 0;
}