+ 4
I have a doubt in code, according to my code's output? In C
Please help me to understand the output of this code...... https://code.sololearn.com/cL2f460tn8dq/?ref=app
5 Answers
+ 7
when,
j=0,
k=0
count=1
and the condition becomes true ,so the second loop breaks.
So then j becomes 1
k again becomes 0 and continue until k=10,
count increases 10
then j becomes again becomes 2 and
again k becomes 0 and continue until k=10
so if we calculate, the total count will be:
1+10+10+10+10+10+10+10+10+10=91.
so the answer is 91
Edit:
if you want the answer 1 then you have to again rewrite this condition(given below) in the first loop and have to predefine the j and k .
if(b[j] == a[0] && b[k] == a[1]){//
break;
}
Then the code would be like that:
https://code.sololearn.com/cBaYqWWsQcO9/#c
+ 7
If you write ++counter inside the if statement then your output will be 1
+ 5
in short you're only break the inner loop in its first iteration.
to get the result of 1, you'll also need to break the outer loop
+ 5
The code is equivalent to
int counter = 1;
for(int j=1;j<10;j++)
for(int k=0;k<10;k++)
++counter;
printf("%d",counter);
Effectively it counts 1+9*10 = 91.
+ 5