+ 4
how is that output possible? ( from a challenge )
int count=1 for (i=1;i<=99;i++) { for (j=1;j<=99;j++) { count++ } cout<<count; } output : 10001
26 Réponses
+ 10
what do you think it should be?
+ 19
This is just a game, my friend not the art of survival in the wood!
So don't worry about that too much since we are human and humans make a lot of dumb mistakes. Enjoy your time. ;)
+ 19
Jay is always good at robbing at the right time! So, don't rush. :D
+ 19
/*******************************************************
* Copyright (C) 2017 Babak Sheykhan
*
* This file is a quiz for Sololearn application.
*
* Quiz can not be copied and/or distributed without the express
* permission of Babak Sheykhan.
*******************************************************/
#include <iostream>
using namespace std;
char blackBox(char &ch) {
int x = -1;
// Step 2:
// in this condition, first, x is compared with itself
// (-1 > -1), then increment by 1. So, it's going to be evaluated
// to false and as a result, else statement will take the program
// flow.
if (x++ > x)
return ++ch;
else
// Step 3:
// As you see, this is a post decrement operator.
// First ch returns to its caller with value of 'b'
// and store in ch2 variable, then decrement by 1 (affect
// the value of ch1 and make it 'a'- based on ASCII table)
return ch--;
}
int main()
{
char ch1 = 'b';
// Step 1:
// Here, ch1 is passed in to blackBox function
// and feed its "alias", so every change that is
// going to be made on ch, will affect ch1, as well.
char ch2 = blackBox(ch1);
// Step 4:
// Here, everything is ready to print out on console
// screen. ch1 = 'a' and ch2 = 'b'.
cout << ch1 << ch2;
}
[https://code.sololearn.com/cIS6yA7MeSh4]
+ 17
#include <iostream>
using namespace std;
int main()
{
int count = 1;
for (int i = 1; i <= 99; i++) {
for (int j = 1; j <= 99; j++)
count++;
cout << count;
}
}
Output:
10019929839749659569479389299110901189128813871486158516841783188219812080217922782377247625752674277328722971307031693268336734663565366437633862396140604159425843574456455546544753485249515050514952485347544655455644574358425941604061396238633764366535663467336832693170307129722873277426752576247723782279218020811982188317841685158614871388128911901091099208930794069505960497039802
+ 16
100 * 100 + 1 = 10001
Look jay's code
+ 15
@ Babak Sheykhan (PERS), a good example 😉
+ 13
@ jay, thanks for your good explanation 😉
+ 12
Fyi for anyone else reading.
For each outer loop, the inner loop counts to 100.
Basically it performs a 100 timetable.
1 - 100
2 - 200
etc,
Since the variable we are storing the sum/result in is initially 1, at the end off outer loop the final result has an extra 1. So instead of being 10,000 it is 10,001
+ 11
You got there though! ok I rob you next time 😀
+ 7
Oh there was stuff wrong as it was presented in your question.
If that how it was presented in the quiz I would report it.
But yeah. It is (when corrected) pretty straight forward when you analyse the code.
Thus I did not want to rob you of the satisfaction of figuring it out for yourself.
This feeling, in my opinion, is pretty good!
+ 6
The code is wrong.
if it worked as is it would be 9802
If you see this again code again in challenges. report it
+ 6
^ exactly.. it should not have been approved.
Questions are submitted and voted upon by the community. As a result some bad questions slip through. Unfortunately this happens.
+ 2
finally i got it. nothing is wrong with this particular code. i just got stucked. shit happends. i hope for questions without mistakes if possible. thank you both..
+ 1
thanks for the answer but i still dont get it. output answer is 10001 when yours starts with 1001
secondly in a challenge is possible the answer not to be full only covering 5 digits?
+ 1
if the code is wrong how it is included in the challenge with that result?
+ 1
oh please rob me! i would say the monent i asked .. i had stucked for long and tired.. anyway jay.. you are right to your basic point..
+ 1
haha! funny like your pic..
0
shit! maby we need more people/questions in the community(so that more choices for the authority of app) or the good ones give more questions or voting allowd only for premium members