KiKi最近学习了信号与系统课程,这门课里有一个非常有趣的函数,单位阶跃函数,其中一种定义方式为:
现在试求单位冲激函数在时域t上的值。
#include<iostream>
using namespace std;
int main()
{
int t;
double result;
while(scanf("%d",&t)!=EOF)
{
if(t<0)
result=0;
else if(t==0)
result=0.5;
else if(t>0)
result=1;
cout<<result<<endl;
}
return 0;
}//求教为什么t用double型就出错?为什么不定义result,直接输出“0/0.5/1”也会报错? #include <stdio.h>
#include <math.h>
int main()
{
int t;//定义整形变量
while(scanf("%d",&t)!=EOF)
{
if(t>0)//if_else语句判断
{
printf("1\n");
}
else if(t==0)
{
printf("0.5\n");
}
else if(t<0)
{
printf("0\n");
}
}
return 0;
}
#include <stdio.h>
int main()
{
int t;
while(scanf("%d",&t)!=EOF)
{
if (t>0)
{printf("1\n");}
else if(t<0)
{printf("0\n");}
else
{printf("0.5\n");}
}
return 0;
} #include <stdio.h>
int main() {
int t, b;
while (scanf("%d", &t) != EOF)
{
if(t>0)
{
printf("1\n");
}
if(t==0)
{
printf("0.5\n");
}
if(t<0)
{
printf("0\n");
}
}
return 0;
}