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);
}
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];
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);
}
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()
{
max = a[i][j];
}
}
// In ma tran
printf(" Ma Tran ");
for(i = 1;i<=n;i++)
{
printf("\n");
for(j = 1;j<=m;j++)
{
printf("%d ",a[i][j]);
}
}
printf(" \n min = %d",min);
printf(" max = %d",max);
getch();
}
Câu 8: Danh sách xóa
#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;
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 xoa(p_hv **pd)
{
p_hv *ptr,*ptim;
{
tao_ds(&p_dau);
hien_ds(p_dau);
xoa(&p_dau);
hien_ds(p_dau);
}
Câu9: Vẽ hình nội tiếp
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#define K 1.73205080
void main()
{
double x,y,x1,x2,y1,y2;
int gd = DETECT,gm;
initgraph(&gd,&gm,"E:\\TC\\BGI");
setcolor(RED);
ellipse(250,250,1,360,100,50);
setcolor(WHITE);
line(150,300,150,200);
line(150,300,350,300);
line(350,300,350,200);
line(350,200,150,200);
setcolor(YELLOW);
circle(250,250,111.8);
setcolor(BROWN);
x = 250;
y = 300;
int i,j;
if (ten=='C')
printf("Ma tran tich %c:\n",ten);
else
printf("Ma tran %c:\n",ten);
for (i=0;i<n;i++)
{
for (j=0;j<m;j++)
printf("%6.2f",a[i][j]);
printf("\n");
}
}
void main()
{
float a[20][20],b[20][20],c[20][20];
int n,p,m,i,j,k;
textmode(C80);
printf("Nhap cac chi so hang cot
n,p,m: "); scanf("%d%d
%d",&n,&p,&m);
nhap_mt(a,n,p,'A');
nhap_mt(b,p,m,'B');
for (i=0;i<n;i++)
for (j=0;j<m;j++)
{
c[i][j]=0;
for (k=0;k<p;k++)
c[i][j]+=a[i][k]*b[k][j];
}
clrscr();
{
tongd = tongd + a[i] ;
sttd ++;
}
}
tbca = (float) tonga/stta;
tbcd = (float) tongd/sttd;
printf(" tong am = %d Trung binh
cong am = %0.2f \n",tonga,tbca);
printf(" tong duong = %d Trung
binh cong duong = %0.2f
\n",tongd,tbcd);
getch();
}
Câu 12:Ma trận tổng theo dạng file
#include <stdio.h>
#include <conio.h>
#include<string.h>
void main()
{
char s[300];
int m,n,tg,i,j,a[50][50],b[50]
[50],c[50][50],k;
FILE *f;
f=fopen("MA_TRAN.C","rt");
fscanf(f,"%d%d", &n,&m);
//Nhap vao ma tran A
fgets(s,300,f);
fgets(s,300,f);
for (i=0;i<n;i++)
}
Câu 13: 3 hình tròn
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#include<alloc.h>
#define K 1.73205080
void tomau2(int xdau ,int ydau,int
xx,int yy,int tg,int color)
{
int i,x ,y;
int a[300] ;
x = xdau -2;
for( i = 0;i<50;i+=2)
{
x = x+2;
y = tg*sqrt((50*50) - (x-
xx)*(x-xx))+yy;
a[i] = x;
a[i+1] = y;
}
a[50] =xdau;
a[51] = ydau;
setcolor(color);
setfillstyle(SOLID_FILL,color);
fillpoly(26,a) ;
}
void tomau(int xdau ,int ydau,int
tomau2(150,100,200,100,1,RED);
tomau(200,150,150,150,-1,RED);
setcolor(YELLOW);
line(150,100,100,150);
setcolor(RED);
line(150,100,200,150);
getch();
}
Câu 14:In ma trận xoay
#include <stdio.h>
#include <conio.h>
void main()
{
int a[20][20],n,so,so_v,v,i,j;
textmode(C80);
printf("Nhap n: "); scanf("%d",&n);
so_v=(n+1)/2;
so=1;
for (v=1;v<=so_v;v++)
{
for (j=v;j<=n-v+1;j++)
a[v][j]=so++;
for (i=v+1;i<=n-v+1;i++)
a[i][n-v+1]=so++;
for (j=n-v;j>=v;j--)
a[n-v+1][j]=so++;
for (i=n-v;i>v;i--)
a[i][v]=so++;
}
printf("Ma tran xoay:\n");
if( ((a2+b2)==c2)||((a2+c2)==b2)||
((c2+b2)==a2) )
{printf("Day LA TAM GIAC
VUONG");}
else
{
if ((a==b)&&(c==b))
{
printf("DAY la Tam giac
deu");
}
else
{
if((a==b)||(c==b)||(a==c))
{
printf("DAY La TAM GIAC
CAN");
}
else
{
printf("TAM GIAC
THUONG");
}
}
}
}
getch();
}
Câu 16:đồ thị y=sin(x) và y=cos(2x)
ymin-5);
}
void ham1()
{
double yc, x = 0.0,x1,y1;
x1 = xtam;
while ( x1 < xmax )
{
y = K * sin(x*RADS);
x1= xtam +x;
y1 =ytam +y;
putpixel(x1, y1, RED);
x += 0.1;
}
x = 0.0;
while(x1>xmin)
{
y = K * sin(x*RADS);
x1= xtam +x;
y1 =ytam +y;
putpixel(x1, y1, RED);
x -= 0.1;
}
}
void ham2()
{
double yc, x = 0.0,x1,y1;
x1 = xtam;
while ( x1 < xmax )
{
closegraph();
}
Câu 17:GDP
#include<stdio.h>
#include<conio.h>
void main()
{
int nam ;
float gdp;
nam = 2000;
gdp = 30;
printf(" Nam GDP\n");
printf("%d
%0.2f\n",nam,gdp);
while(gdp < 60)
{
nam = nam +1;
gdp = gdp* 1.04;
printf("%d
%0.2f\n",nam,gdp);
}
getch();
}
Câu 18: Bánh xe lăn
#include <conio.h>
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#pragma warn -pro
else {x -=1;}
if (x == getmaxx())tg = 1 ;
if(x == 0)tg = 0;
}
closegraph();
getch();
}
Câu 19: Sắp xếp dãy
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void doicho(int *a,int*b)
{
int tg;
tg = *a;
*a = *b;
*b = tg ;
}
void main()
{
int *a,n,i,j;
printf("\nnhap so phan tu cua day
A: ");
scanf("%d",&n);
a=(int*)calloc(n,sizeof(int));
for (i=0;i<n;i++)
{
printf("\nnhap phan tu A[%d] :
",i);
scanf("%d",&a[i]);
} p_node;
p_node *top= NULL;
void push(int n)
{
p_node *p;
p=(p_node*)malloc(sizeof(p_node));
p->chu_so = n;
p->tiep = top;
top = p;
}
int pop()
{
int n;
p_node *p = top;
n = p->chu_so;
top = top->tiep;
free(p);
return n;
}
void doi_cso(int n,int cso)
{
do
{
push(n % cso);
n=n / cso;
}
while (n!=0);
}
void hien_kq(int n,int cso)
{
Đề 11:1 Vẽ cờ
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<alloc.h>
#include<dos.h>
void drawstar(int x,int y,int r)
{
int gd=18,s[12],i;
for(i=0;i<12;i+=2)
{
s[i]=x+r*cos(gd*M_PI/180);
s[i+1]=y-
r*sin(gd*M_PI/180);
gd+=144;
}
setcolor(YELLOW);
setfillstyle(SOLID_FILL,YELLOW);
fillpoly(6,s);
floodfill(x,y,YELLOW);
}
void main()
{ int r=15;
int mh=0,mode;
int x=92,y=50,size,i;
char *p;
initgraph(&mh,&mode,"E:\\TC\\BGI")
;
setcolor(WHITE);
n -= m;
else
m -= n;
if (n == 0)
return m;
else
return n;
}
unsigned BSCNN (unsigned n,
unsigned m)
{
return n * m / USCLN(n, m);
}
void main()
{
unsigned n, m;