Introduction to Programming
Introduction to Programming
Introduction to
Programming Week
1
Dr. Razvan-Ioan “Raz” Dinita
[email protected]
Programming In General
• Programming means:
• Finding a solution to a problem
• Expressing that solution in such a way that a
computer can do it
• Therefore:
• You must understand the problem and its solution
yourself
• Only then can you instruct the computer how to do it
• You must speak the language of the computer; it
doesn’t understand English
Programming In General
• Is programming hard?
• No, but...
• Requires practice – A “perishable” skill
• Requires attention to detail
• Lots of concepts to learn in the
beginning
Programming In General
• “Nothing is
particularly hard if
you divide it into
small jobs” –
Henry Ford
What is a Program?
• Keyboard
• Joystick/Gamepad
• Sensor (e.g. accelerometer)
• Other program
• File
• Camera
Example Outputs
• please note that the ampersand & is required, otherwise scanf will
not be allowed to change the contents of the variable
• other relevant formats
• %hd – captures short type data
• %ld – captures long type data
• %c – captures char type data
• (more formats will follow in future weeks)
Basic Output
• printf(“format”, variable)
• a statement/tool used to output text to the standard/default output
(in our case, the console window)
• The console window is a window that pops up when we run our
programs from Visual Studio. We can see the result of our
programming efforts within them. Only text outputted with printf will be
visible here.
• when the program runs this statement, it writes/outputs to the
console window whatever the “format” tells it to
• “format” can have many forms, but it essentially is a mix of English
and placeholders, the same ones used in scanf (see previous slide)
• optionally, within the text, the newline character \n may be used to
push the text that will follow it to the next line in the console window
• the % placeholders (like %d) are replaced with the data contained
within the variable at the time the printf statement runs:
Basic Input and Output Example
• // represents a single line comment, it is ignored by the program
Basic Input and Output Example
• Output of the example program