15. What will be the value of variables 'm'
and 'n' after the execution of the
following code?
int m, n = 0;
for(m = 1;m <= 4;m++)
n += m;
n--;
(Delhi 2012)
}
Answers
Answered by
2
Answer:
n=-4
m=4
Explanation:
try to do this by solving only first iteration
mark me as braintliest.
Answered by
0
The output of the given code will be n= 6 and m= 5.
Explanation:
In the given code there is some error so, the correct code can be described as follows:
#include <iostream> //defining header file
using namespace std;
int main() //defining main method
{
int m, n = 0; //defining integer variable
for(m = 1;m <= 4;m++) //defining loop that counts m value
{
n += m; // add value in n variable
n--; //decrement the value of n by 1
}
cout<<"n: "<<n<<endl; //print value of n
cout<<"m: "<<m<<endl; //print value of m
return 0;
}
Description of the code:
- In the above program, two integer variable "n and m" is declared, in which variable "n" assigns a value that is equal to 0.
- In the next step, a for loop is declared, which uses variable "m", that starts from 1 and ends when its value is equal to 4.
- Inside the loop variable n adds m variable value and in the next line, variable n decreases its value by 1, and outside the loop, it will prints n, m variable value.
Learn more:
- Output of the code: https://brainly.in/question/14538049
Similar questions