1个回答
2013-10-14
展开全部
#include<graphics.h>
#include<math.h>
#include<stdio.h>
#include<conio.h>float x[3],h[4],y[7];
pro1()
{
int n,i;
float c,k;
printf("please input 3 words for x(n) end with Enter.");
for(i=0;i<=2;i++)
{scanf("%f",&c);<br/>x[i]=c;}
printf("please input 4 words for h(n) end with Enter.");
for(i=0;i<=3;i++)
{scanf("%f",&k);h[i]=k;}for(n=0;n<=2;n++)
{
printf("%f \n",x[n]);
}getch();
for(n=0;n<=3;n++)
{
printf("%f \n",h[n]);
}getch();}
void show()
{
int i=0;
int driver=DETECT,MODE;
initgraph(&driver,&MODE,"");
setbkcolor(0);
cleardevice();
for(i=0;i<=2;i++)
{
setfillstyle(SOLID_FILL,RED);
bar((i+1)*10+20,(int)(400-x[i]*10),(i+1)*10+22,400);
}
printf("x(n)");getch();
cleardevice();
for(i=0;i<=3;i++)
{
setfillstyle(SOLID_FILL,GREEN);
bar((i+1)*10+20,(int)(400-h[i]*10),(i+1)*10+22,400);
}
printf("x2(n)");getch();
cleardevice();for(i=0;i<=7;i++)
{
setfillstyle(SOLID_FILL,CYAN);
bar((i+1)*10+20,(int)(400-y[i]),(i+1)*10+22,400);
}
printf("y(n)=x(n)*h(n);");getch();
cleardevice();
printf("y(n)=x(n)*h(n)\n");
for(i=0;i<=7;i++)
printf("%f ",y[i]);
getch();}convolve()
{
int i,j;
for(i=0;i<=6;i++)
{
float t=0.0;
for(j=0;j<=2;j++)
{
if(i-j>=0&&i-j<=2)
t+=x[j]*h[i-j];
}
y[i]=t;
}
}
main()
{
pro1();
convolve();
show();
}
#include<math.h>
#include<stdio.h>
#include<conio.h>float x[3],h[4],y[7];
pro1()
{
int n,i;
float c,k;
printf("please input 3 words for x(n) end with Enter.");
for(i=0;i<=2;i++)
{scanf("%f",&c);<br/>x[i]=c;}
printf("please input 4 words for h(n) end with Enter.");
for(i=0;i<=3;i++)
{scanf("%f",&k);h[i]=k;}for(n=0;n<=2;n++)
{
printf("%f \n",x[n]);
}getch();
for(n=0;n<=3;n++)
{
printf("%f \n",h[n]);
}getch();}
void show()
{
int i=0;
int driver=DETECT,MODE;
initgraph(&driver,&MODE,"");
setbkcolor(0);
cleardevice();
for(i=0;i<=2;i++)
{
setfillstyle(SOLID_FILL,RED);
bar((i+1)*10+20,(int)(400-x[i]*10),(i+1)*10+22,400);
}
printf("x(n)");getch();
cleardevice();
for(i=0;i<=3;i++)
{
setfillstyle(SOLID_FILL,GREEN);
bar((i+1)*10+20,(int)(400-h[i]*10),(i+1)*10+22,400);
}
printf("x2(n)");getch();
cleardevice();for(i=0;i<=7;i++)
{
setfillstyle(SOLID_FILL,CYAN);
bar((i+1)*10+20,(int)(400-y[i]),(i+1)*10+22,400);
}
printf("y(n)=x(n)*h(n);");getch();
cleardevice();
printf("y(n)=x(n)*h(n)\n");
for(i=0;i<=7;i++)
printf("%f ",y[i]);
getch();}convolve()
{
int i,j;
for(i=0;i<=6;i++)
{
float t=0.0;
for(j=0;j<=2;j++)
{
if(i-j>=0&&i-j<=2)
t+=x[j]*h[i-j];
}
y[i]=t;
}
}
main()
{
pro1();
convolve();
show();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询