接受两个周长 x 和 y 的递归函数.该函数应返回 x 乘以 y.i.e 的值,即 2*4=4+4=
a recursive function that accepts two perimeters x and y. The function should return the value of x times y.i.e 2*4=4+4=
#include<iostream>
using namespace std;
int times(int x ,int y)
{
if(x==0){
return y;
}
else{
cout<< y+(x-1,y);
}
}
int main()
{
int x,y;
cout<<"enter x :";
cin>>x;
cout<<"enter y: ";
cin>>y;
cout<< times(x,y);
cout<<endl;`enter code here`
return 0;
}
int times(int x ,int y)
{
if(x==0){
return 0;
}
return (y + times(x-1,y)); // This is your recursive call.
}
相关文章:
- 数组索引的值没有增加
- 'short int'持有的值溢出,但"自动"不会溢出?
- 是默认情况下分配给char数组常量的值
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 为什么我无法更改"set<set>"循环中的值<int>
- 有效地使用std::unordered_map来插入或增加键的值
- <streamsize>C++ 中 numeric_limits::max() 的值
- 为什么不能修改对象中的值?另外,我如何改进此链表?
- 无法获取webot::PositionSensor对象中位置传感器的值
- 正在将无序映射设置为无序映射的值
- 着色器纹理值与创建纹理时写入的值不同
- 无法按cpp中的值返回矢量
- 指针没有更新它在void函数内部指向的值
- 不能将 "void *" 类型的值分配给类型 "TCHAR" 的实体
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 为什么在我的函数类型后使用引用运算符 (&) 允许我修改它返回的值?
- 为什么当你将函数的返回值乘以零时它不会短路?
- 以C++为单位乘以并显示数组的值
- 为什么当我将 int 乘以双精度时会得到错误的值
- 接受两个周长 x 和 y 的递归函数.该函数应返回 x 乘以 y.i.e 的值,即 2*4=4+4=