0% found this document useful (0 votes)
23 views6 pages

Intro to C Programming Basics

Uploaded by

alexandriaangara
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Intro to C Programming Basics

Uploaded by

alexandriaangara
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

FLORIDA POLYTECHNIC

GUIDED INTRODUCTION TO PROGRAMMING


Introduction and the Print and Scan Functions

Overview:

This guide was created to help students get an early introduction to programming to
create a spark so that students may be interested in pursuing a career in STEM and to
help with programming in the future. This lesson will introduce students to
programming and some terminology that goes along with programming.

Learning Outcomes
-Students will explain the basic concepts programming and coding
-Students will perform basic programming and coding theories

-Students will apply programming and coding procedures to hands on experience exercise
-Students will formulate simple code to get the console to display text and read input.

-Students will utilize the print and scan functions to prompt the user to input values and make a
response to the user with the print function.

Materials

- Computer with internet connection


- Website for the online compiler [Link]
- Lesson 1 Lesson Plan
- Vocabulary Sheet

The Activity

Students will be introduced to the concept of programming using an online compiler to observe and
then create simple programs using code.

Part 1

Let’s start with an answer to a question that some of you may have, “What is programming?”
Programming is the process of creating instructions that tell a computer how to perform a task. We do
this using what we call code. Code is language we use to create the instructions while programming.
There are hundreds of modern code languages that we use to do different things on computers. You
will be focusing on one programming language.

First, start with a very simple introduction to a programming language called C. Question- “Why is it
called ‘C’ that’s a boring name?” While the name is a bit basic it is one of the fundamental programming
languages that most, if not all, programmers need to learn. This is because all modern code can trace
some of its roots back to C.
Print and Scan
This lesson will be on the print and scan function in C. These two functions are the first you usually use
when beginning to program. The print function will take what you put into the function and will output,
or print, it to the computer screen. Along with this the scan function will take an input from the user and
will save the input in variables. By the end of the lesson you will learn to utilize the print and scan
functions to prompt the user to input some values and make a response to the user with the print
function.
In order to get hands on with programming in C we will be using an online compiler, please click or copy
this link to get to a free online compiler [Link] This will be used to practice our
code. While this looks very similar to what we use to program with, it is made to work online and can
vary in some areas, but this gives you a good idea of the tools a programmer uses to do their job.

Part 2

Now this is what you should see when you start up the compiler.

There is already some code there for you to look at. However, before we start, we need to know what
we are looking at.

[Link]/OUTREACH | 863-333-0833 | 4700 Research Way, Lakeland, FL 33805


This left side is where we will be inputting our code. It is very important to not delete what is in the code
right now. If you happen to delete something important, don’t worry just take a look back at the code in
the pictures and just copy it in, or we can just restart by refreshing the page and that will bring you back
to the original code. Doing that will put you back where we started program.

This right side is where we will see the output of our code. This is where we will see the output of our
code when we run it. What the printf function will do is print whatever text you put in it to the console.
To test it on the program, hit the big “Run” button at the top.

After you run the program you should get this output.

And with that Congratulations, you have just run your first working program.

The program you just ran is what most programmers saw when they started. It is known as the “Hello
World” program, the universal start point for most programmers. It’s an appropriate name as all it does
is it outputs the statement “Hello World”.

This is done using the printf function which is formatted like so:
printf(“Blah blah blah\n”);

[Link]/OUTREACH | 863-333-0833 | 4700 Research Way, Lakeland, FL 33805


The \n is used in the printf function to start a new line, we mainly use this to keep our output nice and
neat, otherwise it is just a jumbled mess.

Part 3
Now you can start to make your our own code.

There are a few things to take into consideration when writing code. First, and most importantly, after
you finish writing a line of code you need to end that line with a semicolon which looks like this ‘;’on
your keyboard.
For example, we are going to do a bit of code that will allow you to type your name into the console and
the computer will say hello. Some of the code will be taught later on so to start here is some of the full
code that you will use.

int namechar = 0;
char name[namechar];
printf("Hello World\n");

printf("How many letters are in your name?\n");

//This is where you scan in how many letters are in your name

printf("Now that we know how many letters are in your name, please type in your first name.\n");

//This is where you scan in your name

printf("Hello %s it is nice to meet you.\n", name);


return 0;

Remember to be sure to put this in between the ‘{‘ and the ‘}’ of the int main function for the code to
work. These braces are extremely important to code as they are used to contain instructions for
functions and programs we make. Think of them like writing on a test, if you write everything on the test
paper your teacher will be able to grade it, but if some of it goes on your desk, your teacher cannot
grade what you wrote off the test and on your desk.
Next, you will use the scanf function. The scanf function allows users to input values for variables and
will save them to the appropriate variable. Now, the scanf function is a bit more in depth than the printf
function is because now we have to use the variable we create.

[Link]/OUTREACH | 863-333-0833 | 4700 Research Way, Lakeland, FL 33805


First, one must understand variables. There is an array of variables that each have their own traits and
uses. Today the only variables you need to know for now is the “int” and “char” variables that we will be
using for our scanf. An “int” is an integer, you may or may not have learned about integers in your math
class but if you haven’t, an integer is just a simple number that can be either positive or negative. A
“char” is a variable that holds a character like from the alphabet or punctuation.
Now that we know about the variables we will be using I can now show you how a scanf function if
formatted:

scanf("%variablecaller", &variablename);

This is the exact formatting you use to make a scanf function work.
For today’s lesson though we will need two scanf functions. One for an int and one for a char
The variable caller for an int is “%d” and the variable caller for the char in this case is “%s”.
Now you try and input the scanf into your code and get it to function. You may need to try a few things
before you get it to run properly but don’t get discouraged. If you need help ask your teacher or look up
how code works on the internet, there are hundreds of great sites that can help you with coding. Sites
that are very helpful are places like Stack Overflow, Geeksforgeeks, and W3 Schools. All of these sites
have great explanations on coding principles along with good visuals to help you understand how some
things work. Stack Overflow is especially helpful as it is a free online forum where people can ask for
help with code, the people who use it are usually really nice and help you fix your code.
The way you know your code was done correctly is when your console looks like this after you run and
enter what it asks for.

[Link]/OUTREACH | 863-333-0833 | 4700 Research Way, Lakeland, FL 33805


And with that you have completed your first lesson and introduction into the world of coding.

Assessment

1. Attempt the code above to scan in your name and have the computer say hello.
2. Go to [Link] and write down 3 languages that they have tutorials for.

3. What are 3 other programming languages other than the 3 you saw on [Link]

Additional Resources

- [Link]
- [Link]
- [Link]

Created By:
Ryan Floyd, Computer Science, ‘22

© Florida Polytechnic University, 2020. No part of the materials available may be copied, photocopied,
reproduced, translated or reduced to any electronic medium or machine-readable form, in whole or in part, without
prior written consent of Florida Polytechnic University. Any other reproduction in any form without the permission
of Florida Polytechnic University is prohibited.

Thank you for downloading this lesson, please take a moment to complete our survey

[Link]/OUTREACH | 863-333-0833 | 4700 Research Way, Lakeland, FL 33805

Common questions

Powered by AI

Beginner programmers will achieve multiple learning objectives by creating simple programs using 'print' and 'scan' functions. First, they will gain an understanding of basic syntax and program structure, learning to write clear and error-free code. Second, they will develop the ability to implement user interaction within a program, using 'print' to output messages and 'scan' to input data, thus mastering rudimentary input/output operations. Finally, beginners will learn to apply logic in addressing problems, seeing firsthand how code execution and user feedback work in harmony to achieve a program's goals. These practices lay the groundwork for more complex programming concepts and problem-solving skills .

Using an online compiler like Replit for learning programming in C offers several benefits and potential limitations. On the beneficial side, Replit provides beginners with immediate access to coding and testing environments without the need to install software. This ease of access accelerates the learning process by removing technical barriers, making it ideal for educational settings where quick setup is favored. It supports collaborative learning and experimentation, which are crucial for enhancing engagement and understanding. However, potential limitations include dependency on internet connectivity, which can disrupt learning in areas with unreliable access. Additionally, while Replit offers a user-friendly interface, it may not fully replicate the command-line experience of local compilers, potentially limiting exposure to environment-specific nuances that are critical in professional settings .

Concepts learned through simple programs with printf and scanf lay the foundation for more advanced topics in programming education by instilling crucial skills and understandings. These functions teach basic syntax and structure, providing learners with experience in writing and executing code that elicits user interaction—fundamental skills necessary for more complex programming tasks. Understanding input and output operations enables students to grasp more intricate data processing activities in advanced programming, including dynamic data handling, file I/O, and database operations. Moreover, these initial concepts encourage logical thinking, problem-solving, and debugging skills, all of which are integral for navigating more sophisticated language features like memory management, error handling, or even entering into GUI development .

The "Hello World" program facilitates a beginner's comprehension of program structure and execution flow by providing a simplified and universal starting point that encompasses the basics of writing and running code in C. By constructing this program, novices learn about essential programming elements such as functions, specifically 'printf', code execution order, and syntax including statements and semicolons. It serves as a practical introduction that demystifies the process of translating written code into actions performed by the computer: outputting the phrase "Hello World" to the console. This exercise solidifies their understanding of how source code is compiled, executed, and how its output is displayed, forming a foundational concept in programming .

The 'int' and 'char' variables in C represent different data types that serve unique purposes in a simple C program. An 'int' is an integer data type capable of storing numerical values without decimal points, useful for counting, indexing, or storing other numerical data. In the context of user input and output, an 'int' can be used to store the number of characters in a user's name. The 'char' data type, on the other hand, is used to store individual characters or strings of text. It is ideal for storing and manipulating text data such as a user's name, which is presented as an array of characters. This distinction allows the programmer to utilize these variables appropriately, ensuring that the data is handled efficiently and without type errors that could disrupt program execution .

Online coding communities and resources like Stack Overflow and W3 Schools play a crucial role in enhancing the learning process for novice programmers by providing accessible, diverse, and supportive learning environments. Stack Overflow is particularly valuable as it offers a platform for programming-related inquiries, where users can post questions and receive answers from experienced coders. This real-time feedback and troubleshooting support can significantly reduce learning curves and mitigate frustration from errors. W3 Schools offers educational tutorials that cover various programming languages and principles, supplying both theoretical and practical insights with clear explanations and examples. These platforms cater to different learning preferences by combining community support with structured, self-paced educational content, thus fostering a more well-rounded and interactive learning experience .

The 'print' (printf) and 'scan' (scanf) functions in C are fundamental for beginners as they provide basic input and output operations. The 'print' function allows the programmer to output information to the console, serving as a primary way to communicate with the user through the program. For example, it can be used to display text such as "Hello World" and other messages. The 'scan' function, on the other hand, is used to receive input from the user and store it in variables. These functions are generally some of the first ones a novice learns because they epitomize the interactive capabilities of programming, enabling users to create basic programs that interact with end-users .

Ending a line of code with a semicolon in C is significant because it denotes the end of a statement. Much like a period at the end of a sentence in English, it tells the compiler that the instruction is complete and that it can be executed independently. This punctuation ensures that code is structured correctly and prevents errors during compilation. Failing to include a semicolon typically results in syntax errors, making it one of the most fundamental rules in C programming syntax that programmers must follow to ensure their code runs successfully .

In C programming, writing code within braces ('{' and '}') is crucial for function execution because these braces define the scope and boundaries of code blocks, such as functions, loops, and conditional statements. Code within these braces is treated as a single logical unit, meaning that all instructions inside will be executed in the defined order when the code block is called or triggered. If code is inadvertently placed outside of these braces, it can result in errors or unintended behavior, as the compiler does not recognize it as part of the function. Proper use of braces ensures that all related code is encapsulated correctly, allowing the function to operate as intended, similar to how content within parentheses impacts operations hierarchy in mathematical expressions .

Variable initialization prior to using functions like printf and scanf in a C program is crucial as it prevents undefined behavior by ensuring variables hold valid, predictable values before operations. Uninitialized variables can contain garbage values, potentially leading to erratic program behavior or errors. For example, attempting to scan data into an uninitialized 'int' or 'char' may result in failed storage or unpredictable outputs. Proper initialization, such as setting an 'int' to 0 or declaring an empty 'char' array, provides a starting reference point for operations, ensuring reliability and consistency throughout program execution. This practice embodies programming best practices by supporting code stability and predictability, crucial for debugging and scalability .

You might also like