在C ++中递归公式 [英] Recursing formula in C++

查看:77
本文介绍了在C ++中递归公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



需要一个实现递归公式的代码。公式为:



j *(q(j)=总和(a(i)* b(i)* q(jb(i))

其中i = 1到2,j = 1到6.



谢谢





PS(从评论中添加):

Hello,

Need a code for implementation of a recursion formula. Formula is:

j*(q(j) = Sum (a(i)*b(i)*q(j-b(i))
where i=1 to 2 and j=1 to 6.

Thanks


P.S. (added from comments):

#include <stdio.h>
main(){
       int a[2],b[2],k[2];
       float s[2],q[6];
       int i,j;
       float sum;
       a[0]=0;
       b[0]=0;
       for (i=0;i<2;i++){
           printf("Call category %d\n",i+1);
           printf("Input a%d ",i+1);
           scanf("%f", &a[i]);
           printf("Input b%d ",i+1);
           scanf("%f", &b[i]);
           }
       q[0]=1;
       for(j=1;j<7;j++){
          sum=0;
          k[0]=0; 
          k[1]=0; 
          s[0]=0;
          s[1]=0;          
          for (i=0;i<2;i++){
              k[i]=j-b[i];
              if (k[i]<0){                  
                  q[k[i]]=0;
                  }                    
              if (k[i]==0){
                  q[k[i]]=1;
                  }
              s[i]=a[i]*b[i]*q[k[i]]; 
              sum=sum+s[i];                     
              }
          q[j]=sum/j;
          } 
       printf("\nq[0]= 1\n");
       for (j=1;j<7;j++){
           printf("q[%d]= %f\n",j,q[j]);
           }
       scanf("\n"); 
      }

推荐答案

我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是你想的很难!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!


需要一个方向来解决这个问题。如果您有任何请提供。

谢谢
Need a direction for solving this problem. If you have any please provide.
Thank you


什么是正确的代码?

如何更改此部分。

if(k [i]< 0){

q [k [i]] = 0;

}
What is the right code?
How can I change this part.
if (k[i]<0){
q[k[i]]=0;
}


这篇关于在C ++中递归公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆