Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

FAO lập trình C do sinh viên KMA giải
MIỄN PHÍ
Số trang
7
Kích thước
60.4 KB
Định dạng
PDF
Lượt xem
1553

FAO lập trình C do sinh viên KMA giải

Nội dung xem thử

Mô tả chi tiết

Câu 1:

// giai he phuong trinh bac nhat

#include <stdio.h>

#include <conio.h>

void main()

{

float a, b, c, d, m,n;

float D, Dx, Dy;

clrscr();

printf("nhap he so cua pt1 a, b, m:

");

scanf("%f%f%f", &a,&b,&m);

printf("nhap he so cua pt1 c, d, n:

");

scanf("%f%f%f", &c,&d,&n);

D = a*d - b*c;

Dx = m*d - n*b;

Dy = a*n - c*m;

if(D==0)

{

if(Dx==0&&Dy==0)

printf("hpt co vo so

nghiem!");

else

printf("hpt co vo nghiem!");

}

else

{

printf("Nghiem cua

hpt:\n");

printf("x= %6.2f\n", Dx/D);

printf("y= %6.2f", Dy/D);

}

getch();

}

/* Cau3 - Giai phuong trinh bac hai

AXư + BX + C = 0 */

#include <stdio.h>

#include<conio.h>

#include <math.h>

void main()

{

float a, b, c, delta;

printf("\nGiai phuong trinh bac hai

AXư + BX + C = 0");

printf("\nCho biet ba he so A B C :

");

scanf("%f%f%f", &a, &b, &c);

delta = b * b - 4 * a * c;

if (delta<0)

printf("Phuong trinh vo nghiem");

else if (delta == 0)

printf("Phuong trinh co nghiem

kep x1 = x2 = %0.2f", -b/(2*a));

else

{

printf("Phuong trinh co hai nghiem

phan biet\nx1 = %0.2f", (-b +

sqrt(delta))/(2*a));

printf("\nx2 = %0.2f", (-b -

sqrt(delta))/(2*a));

}

getch();

}

Cấu 5 Nhập vào 1 dãy n số bất kì

.Tìm giá trị max min cùng vị trí của

mỗi giá trị trong dãy

#include<stdio.h>

#include<alloc.h>

#include<conio.h>

void main()

{

int *a,i,n,min,max,vtmin,vtmax;

printf("n = ");scanf("%d",&n);

a = (int*)malloc(n*sizeof(int));

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

{

printf(" a[%d] = ",i);

scanf("%d",&a[i]);

}

min = a[1];max = a[1];

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

{

if(min > a[i])

{

min = a[i];

vtmin = i;

}

if(max < a[i])

{

max = a[i];

vtmax = i;

}

}

printf(" max la a[%d] =

%d",vtmax,max);

printf(" min la a[%d] =

%d",vtmin,min);

getch();

}

Câu6:chèn danh sách sinh viên

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

#include<string.h>

typedef struct hoc_vien

{

char ho_ten[20];

int tuoi;

float d_tb;

struct hoc_vien *tiep;

}p_hv;

p_hv *p_dau,*p;

void tao_ds(p_hv **pd)

{

char ht[20];

float x;int tuoihv;

printf("Nhap danh sach (ket thuc

bang nhap ho ten trong)\n");

*pd=NULL;

do

{

fflush(stdin);

printf("Ho ten:");

gets(ht);

if(ht[0]!=0)

{

if(*pd==NULL)

{

*pd=(p_hv*)malloc(sizeof(p_hv));

p=*pd;

}

else

{

p-

>tiep=(p_hv*)malloc(sizeof(p_hv));

p=p->tiep;

}

strcpy(p->ho_ten,ht);

p->tiep=NULL;

printf("Tuoi :");

scanf("%d",&tuoihv);

p->tuoi = tuoihv;

printf("Diem trung binh:");

scanf("%f",&x);

p->d_tb = x;

}

}while(ht[0]!=0);

}

void hien_ds(p_hv *pd)

{

int stt=0;

printf(" DANH SACH HOC

VIEN\n");

printf("

==================\n");

printf(" STT HO_TEN

TUOI DIEM_TB\n");

p=pd;

while(p!=NULL)

{

printf(" %d %s %d

%0.2f\n",++stt,p->ho_ten,p->tuoi,p-

>d_tb);

p=p->tiep;

}

getch();

}

void chen(p_hv *pd)

{

p_hv *ptim;

char ht[20];

float x; int tuoihv;

fflush(stdin);

p=(p_hv*)malloc(sizeof(p_hv));

p->tiep=NULL;

printf("\nHo ten nguoi can chen:");

gets(p->ho_ten);

printf("Tuoi :");

scanf("%d",&tuoihv);

p->tuoi = tuoihv;

printf("Diem trung binh:");

scanf("%f",&x);

p->d_tb=x;

printf("Muon chen vao sau hoc vien

nao:");

fflush(stdin);

ptim=pd;

gets(ht);

while((ptim!=NULL) &&

strcmpi(ptim->ho_ten,ht))

ptim=ptim->tiep;

if(ptim==NULL)

printf("Khong tim thay vi tri chen!");

else

{//tim thay o cuoi

if(ptim->tiep==NULL)

ptim->tiep=p;

else

{

p->tiep=ptim->tiep;

ptim->tiep=p;

printf("da chen xong!");

}

}

printf("Da chen xong!");

getch();

}

void main()

{

tao_ds(&p_dau);

hien_ds(p_dau);

chen(p_dau);

hien_ds(p_dau);

}

Câu 7:Matrix max min

Tải ngay đi em, còn do dự, trời tối mất!