xu ly so tin hieu
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<dos.h>
int x[200],y[200],h[200],t[200];
int i,j,n,m,max;
void dapungxung()
{ int i;
printf("
nhap so cac dap ung xung n = ");
scanf("
%d",&n);
for(i=0;i<n;i++)
{ printf("
\t h[%d] = ",i);
scanf("%d",&h[i]);
}
}
void tinhieutre(int k)
{ int i;
for(i=0;i<n;i++)
t[i]=k*h[i];
}
void tinhieuvao()
{ int i,j;
printf("
nhap cac so tin hieu vao : m = ",m);
scanf("%d",&m);
for(j=0;j<m;j++)
{
printf("
\t x[%d] = ",j);
scanf("%d",&x[j]);
}
}
void tinhieura()
{
int j,l,k;
j=0;
for(j=0;j<m;j++)
{ tinhieutre(x[j]);
l=j;
for(k=0;k<n;k++)
{
y[l]+=t[k];
l++;
}
}
printf("
tin hieu ra y(n) : ");
n=n+m-1;
for(i=0;i<n;i++)
{
printf(" %4d ",y[i]);
if(max<abs(y[i]))
max=abs(y[i]);
}
}
void ktdh()
{ int gd=DETECT,gm;
initgraph(&gd,&gm," ");
if(graphresult()!=grOk) exit(1);
}
void ve()
{
int i,j,dx,dy;
char *st1,*st2;
setcolor(LIGHTMAGENTA);
rectangle(5,5,getmaxx()-10,getmaxy()-10);
setcolor(LIGHTGREEN);
outtextxy(getmaxx()-38,getmaxy()/2-3,">");
line(15,getmaxy()/2,getmaxx()-40,getmaxy()/2);
setcolor(RED);
outtextxy(getmaxx()-200,getmaxy()/2-200,"bai thuc hanh so 1 XLTHS");
outtextxy(getmaxx()-20,getmaxy()/2-15,"n");
outtextxy(getmaxx()-80,getmaxy()/2-40,"y(n)");
setcolor(6);
outtextxy(450,450,"Tin hieu ra");
setbkcolor(0);
dx=(getmaxx()-150)/(n+m);
dy=(getmaxy()/2-20)/max;
for(i=0;i<n;i++)
{
setcolor(LIGHTRED);
line(60+dx*i,getmaxy()/2,60+dx*i,getmaxy()/2-(int)(y[i]*dy));
setcolor(LIGHTBLUE);
circle(60+dx*i,getmaxy()/2-(int)(y[i]*dy),2);
setcolor(CYAN);
sprintf(st1,"%d",y[i]);
outtextxy(70+dx*i,getmaxy()/2-(int)(y[i]*dy),st1);
setcolor(LIGHTMAGENTA);
sprintf(st2,"%d",i);
outtextxy(50+dx*i,getmaxy()/2+10,st2);
}
getch();
closegraph();
}
void main()
{
clrscr();
tinhieuvao();
dapungxung();
tinhieura();
getch();
ktdh();
ve();
getch();
}
Bạn đang đọc truyện trên: Truyen247.Pro