The function is supposed to multiply the values together. You don't have any multiplication at all. Also, you should write a separate function rather than just put the code inside main().
The initial value of i in the loop should not be zero.
The test if (m <= n) should be done before the start of the for loop. Think about what would happen to the loop if m was greater than n.
Perhaps you should consider some examples of what this means:
m*(m+1)*...*n
Let's say for example m = 4 and n = 7
then the function should calculate the result of 4 * 5 * 6 * 7 giving the result 840.
#include <iostream>
usingnamespace std;
int main()
{
int i;
int n;
int m = 1;
cout <<" Enter Number : ";
cin >> n;
for(i=1; i <= n; i = i+1){
cout << i <<endl;
m = m * (m + i);
}
cout <<"the summiation is = "<<m<<endl;
system("pause");
}
#include <iostream>
usingnamespace std;
int main()
{
int n;
int m = 1;
cout <<" Enter N Number : ";
cin >> n;
for(int i=1; i <= n; i++){
cout << i <<endl;
m = m * i;
}
cout <<"The Total Multiplication = "<<m<<endl;
system("pause");
}
#include <iostream>
int f (int n, int m)
{
// do some processing with m and n here
return result;
}
usingnamespace std;
int main()
{
int n, m;
cout << "Enter first number: ";
cin >> n;
cout << "Enter second number: ";
cin >> m;
cout << "Answer is: " << f(n, m) << endl;
return 0;
}
Your task is to fill in the details of function f(n, m) (lines 3 through 7). What you have so far is leading in that direction but is still incomplete.
#include<iostream>
usingnamespace std;
int f(int m, int n)
{
int x = 1;
for (int i = 0; i <= n; i++)
{
x = x * (m + i);
}
return x;
}
void main()
{
int m;
int n;
cout <<" M "<<endl;
cin >> m;
cout<<" N "<<endl;
cin >> n;
int x = f(m, n);
cout << x << endl;
system("Pause");
}
Well..I'm not sure if that's quite the logic you were going for, because when I run it in my end, with sample input m = 5 and n = 9, I get -662538496
What are the exact instructions your professor gave you? Because your first post and your last post (in terms of the logic in your code) are saying two very different things.