+ 2
How to print this pattern in simple way???
1 11 121 1331 14641 here my attempt but how i print 1 https://code.sololearn.com/cRyPj4ti79YX/?ref=app [A^dr3w] Dan Walker Dev Hans Larry Sreejith Arun Tomar Fata1 Err0r
17 Réponses
+ 8
Hint:
1= 11 ^ 0
11= 11 ^ 1
121= 11 ^ 2
1331= 11 ^ 3
14641= 11 ^ 4
.......
+ 3
Harsh Agrawal you're so close and the hint KrOW gave should help, you'll learn much better if you solve it yourself
+ 2
Harsh Agrawal I think we thought you were going to add a new code to apply the hints, but the code looks the same.
As I said, you are so close so try a few things and see if you get what you want
+ 1
Harsh Agrawal most of programming is stuff not working, and the coder having to puzzle out how to fix it. That is as valuable a skill as knowing the language syntax :)
+ 1
Harsh Agrawal what I will say is, double check your approach. Your second for loop will only ever execute one time because it starts and ends at i. Do you want to multiply p=1 by 11 some number of times, or keep the previous value of p and multiply it by 11 on the next iteration? This may help
+ 1
Harsh Agrawal p starts at 1, so why do you get 11 come out first?
(also remove the second for loop, it actually isn't doing anything a single line of code wouldn't do)
+ 1
Harsh Agrawal this is the root of your problem - the inner loop only executes once on every round of the outer loop (j=i; j<=i; i++) so if you make it false for first, it will be false for all. This should be removed, because a single line will do the same thing.
What I'm getting at is that you multiply and then print. Is this the correct order?
There is an alternative solution keeping the inner loop, but you must start it from 1 and have int p = 1 inside the outer for loop.
I'm not quite sure why you have the second loop, see one of previous answers (i.e. do you want to multiply up from one, increasing the number of times this occurs on each loop, or multiply by 11 each time)
+ 1
Harsh Agrawal I wrong or its same code like first post?
+ 1
Dan Walker Exactly
+ 1
Harsh Agrawal
is this a pascal triangle or powers of 11? (seems like pascal triangle)
I am assuming, it's powers of 11.
As Dan Walker said, you don't need a second for loop (literally, it does nothing) , instead
1. use an if statement or
2. print your answer before calculation
both will print 1 first.
0
KrOW can u do in my program
0
Dan Walker ya but its working so please!!!!
0
Dan Walker but how wll i get 1 if i do so den some line is missimg i.e.main problem with me in this
0
Dan Walker i want to false 1st condition when it is going from inner loop as it is not false so 1*11=11 get so i want to make the condition first false so it wll print 1 but how???
0
Dan Walker can u please check my program ,make it right n send it here
0
KrOW I did not understand what u say?? can u elaborate?
0
thnxzzz all of u i got my problem