2011-05-23, 12:30 AM
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
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);
}
}

