I've been reading some depressing stories about programming when a bit caught my eye:
Quote:If you can successfully write a loop that goes from 1 to 10 in every language on your resume, can do simple arithmetic without a calculator, and can use recursion to solve a real problem, you're already ahead of the pack!
Makes me wonder, how many ways can Southperry count to 10? Anything that a computer can run to print an output counts. JavaScript to C++. Python to Assembly.
Guidelines:
Using a language multiple times is fine, as long as the methodologies are different.
The quote says "loop". Don't hardcode it in. eg: Don't type out 1 through 10 and have the program print it out.
Simpler, more elegant solutions are better. Strive for those.
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).
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);
dante9898 Wrote: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
dante9898 Wrote: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).
C is a low level language, it does not have any natural ways to print values without explicitly casting them into a character string via a format conversion function like printf. The other languages you can just say print @variable and the engine knows to bring the value of the variable, but with C you have to be more specific, because print requires a character string and x is a number, therefore you need to convert x into a character string to print it, either via that function, or a more torturous route such as creating a character array and printing to that array the value of the variable. Could've possibly done a print( itoa(x)); as well.
It's not having what you want - It's wanting what you've got.
Pretty much yes. I remember that i was taught that but forgot about it, while i got caught up recently on a problem that needed to find if a number was Odd and Even and could not remember the method to do so.
Eosian Wrote:C is a low level language, it does not have any natural ways to print values without explicitly casting them into a character string via a format conversion function like printf. The other languages you can just say print @variable and the engine knows to bring the value of the variable, but with C you have to be more specific, because print requires a character string and x is a number, therefore you need to convert x into a character string to print it, either via that function, or a more torturous route such as creating a character array and printing to that array the value of the variable. Could've possibly done a print( itoa(x)); as well.
This is still a little fuzzy but i can understand my way from what you and kalovale said, need to see it in action to completely understand it. Thx for the answers btw.
GMSInfighter Wrote:Jeez, I gotta re-learn all this stuff. Haven't in years.
I would post binary code but that's too simple compared to what you guys wrote =3=