Loops 我的程序怎么了?卡在计算循环中或函数调用失败?
这是我的节目。我不明白这是怎么回事。在我给出输入之后,什么也没有发生。我猜程序卡在了计算循环中,或者我无法在循环中调用事实函数。关于问题应该在哪里的想法Loops 我的程序怎么了?卡在计算循环中或函数调用失败?,loops,math,function-call,Loops,Math,Function Call,这是我的节目。我不明白这是怎么回事。在我给出输入之后,什么也没有发生。我猜程序卡在了计算循环中,或者我无法在循环中调用事实函数。关于问题应该在哪里的想法 #include<iostream> #include<math.h> using namespace std; int fact(int a) { int f=0; for(int i=1; i<=a;i++) f=f*i; } main() { double x,temp1,t
#include<iostream>
#include<math.h>
using namespace std;
int fact(int a)
{
int f=0;
for(int i=1; i<=a;i++)
f=f*i;
}
main()
{
double x,temp1,temp2,sine;
int p,n;
temp1=temp2=0;
cout<<"Enter the value of x: ";
cin>>x;
cout<<"\nEnter the length of series: ";
cin>>n;
if(n%2==0)
{
for(p=1;p<=n-1;p+4)
{
temp1=temp1+(pow(x,p)/fact(p));
}
for(p=3;p<=n-1;p+4)
{
temp2=(temp2+pow(x,p)/fact(p))*(-1);
}
}
else
{
for(p=1;p<=n;p+4)
{
temp1=temp1+(pow(x,p)/fact(p));
}
for(p=3;p<=n;p+4)
{
temp2=-(temp2+pow(x,p)/fact(p));
}
}
sine=temp1+temp2;
cout<<"\nsinx= "<<sine;
}
检查这个
int fact(int a)
{
int f=1;
for(int i=1; i<=a;i++)
f=f*i;
}
p+4在for循环的增量部分做什么?另外,您没有从int-fact返回任何值。p=p+4在for循环中,我猜是的,增量有问题。谢谢。我们不能用它代替p++吗?我认为这只是一个条件,将其移动到循环中起作用。谢谢。@PavanKGuduru p++与p=p+1相同,而不是p+1。还有一个作业也在现场。谢谢。换了。但问题在于循环中的增量。