Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

cslt bai tap chuong 6

Chương 6:

1.

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

void sx(float *ds,int *n)

{int *i,*j;float *temp;

i=(int*) malloc(2);

j=(int*) malloc(2);

temp=(float*)malloc(4);

for (*i=0;*i<*n-1;(*i)++)

 for (*j=*i+1;*j<*n;(*j)++)

          if (ds[*i]>ds[*j])

          {*temp=ds[*i];

          ds[*i]=ds[*j];

          ds[*j]=*temp;

          }

}

main()

{int *i,*n;float *ds,*rds;

clrscr();

n=(int*)malloc(2);

printf("Moi ban nhap so luong phan tu: ");

scanf("%d",n);

i=(int*)malloc(2);

rds=ds=(float*)malloc(*n*4);

for (*i=0;*i<*n;(*i)++)

{       clrscr();

          printf("Moi ban nhap phan tu thu %d: ",*i+1);

          scanf("%f",ds++);

}

clrscr();

printf("Day vua nhap la

");

ds=rds;

for (*i=0;*i<*n;(*i)++)

          printf("%.2f ",*ds++);

sx(rds,n);

printf("

Day sap xep theo tang dan la:

");

ds=rds;

for (*i=0;*i<*n;(*i)++)

          printf("%.2f ",*(ds+*i));

getch();

}

2.

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

int dc_chinh(int *mt,int *n)

{int *i,*t;

i=(int*)malloc(2);

t=(int*)malloc(2);

*t=1;

for (*i=0;*i<*n;(*i)++)

          (*t)*=(*(mt+*i+(*i)*(*n)));

return *t;

}

int dc_phu(int *mt,int *n)

{int *i,*t;

i=(int*)malloc(2);

t=(int*)malloc(2);

*t=1;

for (*i=0;*i<*n;(*i)++)

          (*t)*=(*(mt+*n-*i-1+(*i)*(*n)));

return *t;

}

main()

{int *i,*j,*mt,*n;

i=(int*)malloc(2);

j=(int*)malloc(2);

n=(int*)malloc(2);

clrscr();

printf("Moi ban nhap so chieu cua mtran vuong: ");

scanf("%d",n);

mt=(int*)malloc((*n)*(*n)*2);

for (*i=0;*i<*n;(*i)++)

          for (*j=0;*j<*n;(*j)++)

          {

                    printf("Nhap ptu[%d,%d]= ",*i+1,*j+1);

                    scanf("%d",mt+*j+(*i)*(*n));

          }

clrscr();

printf("Tich duong cheo chinh la %d, duong cheo phu la %d",dc_chinh(mt,n),dc_phu(mt,n));

getch();

}

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: