乘法函数给出一个恒定的随机数

multiplication function giving a constant random number

本文关键字:一个 随机数 函数      更新时间:2023-10-16

我是C++的初学者,我只是在学习函数。我的程序运行,但是,它给出了一个对我来说没有任何意义的常量数字。无论如何,这是我的代码,谢谢。

#include <iostream>
using namespace std;

       int multiplication (int x , int s)
       {
            int v;
            s=x*s;
             return v;
      }
           int main (){
        int u,k,l;
          cout<<"enter two numbers"<<endl;
           cin>>k;
            cin>>l;
          u =    multiplication ( k , l);
          cout <<"the result is "<<u<<endl;
           return 0 ;


        }
int multiplication (int x , int s)
{
    int v;
    s=x*s;
    return v;
}
  1. 创建一个变量v 。当前v保存一个未初始化(不可预测)的值。
  2. s设置为乘法的结果。现在s保存多属性的结果,v仍然保存不可预测的值。
  3. 返回 v 的值(不可预测)。

你的意思是写return s;,还是v=x*s;