Once you attempt the question then PrepInsta explanation will be displayed.
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
a=6,b=84;
while(b>0)
{
b=b/2;
a=a+6;
c=a+b;
while(c>40)
{
if(c%2 == 0)
cout<<a;
else
cout<<b;
c=c/10;
}
}
cout<<c;
return 0;
}
Lets understand it step by step
initially a=6 , b=84
compiler will enter while loop
1st iteration – b=42 , a=12, c= a+b = 54(compiler will enter 2nd while loop)
(if condition gets true) – it will print a = 12
2nd iteration – b=21, a=18, c= a+b = 39(compiler will not enter 2nd while loop)
3rd iteration – b=10, a=24, c= a+b = 34(compiler will not enter 2nd while loop)
4th iteration – b=5, a=10, c= a+b = 35(compiler will not enter 2nd while loop)
5th iteration – b=2, a=36, c= a+b = 38(compiler will not enter 2nd while loop)
6th iteration – b=1, a=42, c= a+b = 43(compiler will enter 2nd while loop)
(if condition gets false), else will be executed and it will print b – 1
now, c=c/10, that makes c=4
7th iteration – b=0, a=48, c= a+b = 48(compiler will enter 2nd while loop)
(if condition gets true), it will print a – 48
now, c=c/10, that makes c=4
compiler get out of both the while loops
it will print c – that is 4
Hence the output will be
12 1 48 4
We hope, this will solve out your queries