Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count to 10
#6
dante9898 Wrote:I would give you a brohug if i were in front of you.

This reminded me that i had to look up ways to find how to know when a number is even or odd while making algorithms (And later coding it), and now i remembered how to calculate multiples of any number to boot too Biggrin

Im still fairly new to programing and have to restart my education of it because of a few problems that i won't bother mention, but someone would be nice to explain this to me? "printf( "%d\n", x)" only one that didn't understand exactly what it says (I can guess, sort of, but i would rather know exactly what it is).

printf can be read as "print formatted", that is, printing something to the output in a formatted manner. You can dictate that the thing you print be an interger (d), a floating point value (f), a string (s) or possibly more. Basically, it's a function, it receives order to do something and HOW to do it, then do it.

In your example: printf("%d\n", x) says to print x (whatever it may be) as an integer (%d part) - so it probably will cut off the decimal part if x is a floating point value.
The \n part, if I'm not mistaken, universally means "insert a newline" where \ is the escape sequence so that n could mean new (and not the literal character n).

As for the actual topic, I only know Java as of now (so probably I can do it in C and C++ after a 10-minute session digging up?), and here's the most obvious ways:
Code:
for(int i=1; i <=10; i++) {
   System.out.println(i);
}
Code:
int i = 1;
do {
   System.out.println(i++);
} while (i <= 10);
Code:
public static void addOne(int i) {
   if(i < 10) {
      i++;
      System.out.println(i);
      addOne(i);
   }
}
Reply


Messages In This Thread
Count to 10 - by Hazzy - 2011-05-22, 11:24 PM
Count to 10 - by Erebus - 2011-05-22, 11:34 PM
Count to 10 - by Hazzy - 2011-05-22, 11:35 PM
Count to 10 - by Eos - 2011-05-22, 11:52 PM
Count to 10 - by FenixR - 2011-05-22, 11:53 PM
Count to 10 - by Kalovale - 2011-05-23, 12:30 AM
Count to 10 - by Eos - 2011-05-23, 12:37 AM
Count to 10 - by shouri - 2011-05-23, 12:45 AM
Count to 10 - by FenixR - 2011-05-23, 12:54 AM
Count to 10 - by Fiel - 2011-05-23, 01:04 AM
Count to 10 - by Hazzy - 2011-05-23, 01:04 AM
Count to 10 - by shouri - 2011-05-23, 01:16 AM
Count to 10 - by Eos - 2011-05-23, 01:21 AM
Count to 10 - by Kalovale - 2011-05-23, 01:25 AM
Count to 10 - by GMSInfighter - 2011-05-23, 01:27 AM
Count to 10 - by Fiel - 2011-05-23, 01:29 AM
Count to 10 - by Luacake - 2011-05-23, 01:34 AM
Count to 10 - by Eos - 2011-05-23, 01:37 AM
Count to 10 - by Fiel - 2011-05-23, 01:39 AM
Count to 10 - by Eos - 2011-05-23, 01:41 AM
Count to 10 - by GMSInfighter - 2011-05-23, 01:49 AM
Count to 10 - by Erebus - 2011-05-23, 01:58 AM
Count to 10 - by shouri - 2011-05-23, 02:06 AM
Count to 10 - by Luacake - 2011-05-23, 02:43 AM
Count to 10 - by Loose - 2011-05-23, 03:51 AM
Count to 10 - by Hazzy - 2011-05-23, 01:59 PM
Count to 10 - by OB3LISK - 2011-05-23, 04:44 PM
Count to 10 - by Nikkey - 2011-05-23, 06:04 PM
Count to 10 - by Shidoshi - 2011-05-23, 06:10 PM
Count to 10 - by Luacake - 2011-05-24, 02:05 AM
Count to 10 - by Stereo - 2011-05-24, 02:37 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)