![]() |
|
[C] print numbers with loop side by side - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] print numbers with loop side by side (/showthread.php?tid=4754184) |
print numbers with loop side by side - telmo_d - Mar 30, 2015 I have too create an output similar to this for input 5. 15 24 33 42 51 I have the code below but its just printing me this: 5 1 2 3 4 5 I don't understand why. Why is that? Code #include <stdio.h>* - TheComet - Mar 30, 2015 A much easier solution: PHP Code * - telmo_d - Mar 30, 2015 (Mar 30, 2015 05:48 AM)TheComet Wrote: A much easier solution: That's a nice solution. I have to really think all my options next time but i've been reading nested for loops and decided to aplly that, clearly i have trouble with them. Could you change the code to make it work? I can't see what's wrng. * - TheComet - Mar 30, 2015 Quote:i've been reading nested for loops and decided to aplly that It's not a nested loop problem. You cannot solve this using nested loops, because the output of nested loops would be n^2, but you only have n outputs. * - Sights101 - Mar 30, 2015 You could do a two variable for loop if its easier for you to visualize... Code #include <iostream>* - 0xDEAD10CC - Mar 30, 2015 I don't know why you guys are making this so difficult... Anyone notice that the values are increments of 9? lol! 🤝 Here, a good mathematical way to solve this: Code int input = 9;Works for 1 >= input <= 9.. I wouldn't know what kind of output you'd expect if input was 0... Perhaps just "0"? or "00"? (Your example starts at 1 however)... Or if input was greater than 9. |