0% found this document useful (0 votes)
6 views

7.-Introduction-to-C

The document serves as an introduction to programming, focusing on the importance of programming languages, specifically C. It outlines the structure of a C program, including header files, main method declaration, variable declaration, and the use of escape sequences. Additionally, it discusses the benefits of learning programming, such as career opportunities and high salaries.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

7.-Introduction-to-C

The document serves as an introduction to programming, focusing on the importance of programming languages, specifically C. It outlines the structure of a C program, including header files, main method declaration, variable declaration, and the use of escape sequences. Additionally, it discusses the benefits of learning programming, such as career opportunities and high salaries.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

INTRODUCTION

TO PROGRAMMING

PREPARED BY: ENGR. JONICIO A. DACUYA


Instructor
For Example: Adding 2
numbers,
Rounding off a number, etc.
“Instruct the computer”: this basically Just like we humans can
means that you provide the computer a set understand a few languages

1 of instructions that are written in a language


WHAT IS
that the computer can understand. The
(English, Spanish, Mandarin,
French, etc.), so is the case
with computers. Computers
instructions could be of various types.
PROGRAMMING? understand instructions that
are written in a specific
syntactical form called a
For example:
“Perform various tasks”: the tasks could

2
programming language.
be simple ones like we discussed above Calculating simple interest, given
(adding 2 numbers, rounding off a number) principal, rate and time.
or complex ones which may involve a Calculating the average return on a
sequence of multiple instructions stock over the last 5 years.
The above 2 tasks require complex
Programming is a way to tell calculations. They cannot usually
be expressed in simple instructions
computers to do a specific task. like adding 2 numbers, etc.
Why should you learn
Computer
Programming?
Programming is fun: Using Programming,
you can create your own games, your
personal blog/profile page, a social
networking site like Facebook, a search
engine like Google or an e-commerce
platform like Amazon! Won’t that be fun?
Imagine creating your own game and putting
it on Play Store and getting thousands and
thousands of downloads!
Why should you learn
Computer
Programming?
The backbone of a Technology
Company: The backbones of today’s
technology companies like Google, Facebook,
Microsoft, Apple, Amazon, and many others,
are giant computer programs written by a
collaboration of thousands of skilled
programmers. If you have the right business
acumen, knowing programming can help you
create the next big tech company.
Why should you learn
Computer
Programming?
Pretty good salary: Computer
Programmers are paid extremely well almost
all across the world. Top programmers in
Silicon Valley make millions of dollars every
year. Quite a few companies offer to start
salaries as high as $100,000 per year.
C
PROGRAMMING
C is a procedural programming
language.
It was initially developed by Dennis Ritchie
in the year 1972. It was mainly developed as
a system programming language to write an
operating system.

The main features of the C language include


low-level memory access, a simple set of
keywords, and a clean style, these features
make C language suitable for system
programming's like an operating system or
compiler development.
Why learn C?

1. It is one of the most popular programming language in


the world

2. If you know C, you will have no problem to learn other


popular programming languages such as Java, Python,
C++, C#, etc, as the syntax is similar

3. C is very fast, compared to other programming


languages, like Java and Python

4. C is very versatile; it can be used in both applications


and technologies
C LANGUAGE
STRUCTURE
Header Files Inclusion:

The first and foremost component is the inclusion of the


Header files in a C program.
A header file is a file with extension .h which contains C
function declarations and macro definitions to be shared
between several source files.
Some of C Header files:
1. stddef.h – Defines several useful types and
macros.
2. stdint.h – Defines exact width integer types.
3. stdio.h – Defines core input and output functions
4. stdlib.h – Defines numeric conversion functions,
pseudo-random network generator, memory
allocation
5. string.h – Defines string handling functions
6. math.h – Defines common mathematical functions
Main Method Declaration:

The next part of a C program is to declare the main()


function. The syntax to declare the main function is:

int main()
{

Body of Program

}
Variable Declaration:

The next part of any C program is the variable


declaration. It refers to the variables that are to be
used in the function. Please note that in the C
program, no variable can be used without being
declared. Also in a C program, the variables are to be
declared before any operation in the function.
Body:

The body of a function in the C program, refers to the


operations that are performed in the functions. It can
be anything like manipulations, searching, sorting,
printing, etc.
Return statement.

The return statement refers to the returning of the


values from a function. This return statement and
return value depend upon the return type of the
function. For example, if the return type is void, then
there will be no return statement. In any other case,
there will be a return statement and the return value
will be of the type of the specified return type.
Line 1: [ #include <stdio.h> ]
#include <stdio.h>
In a C program, all lines that start with # are processed by
int main(void)
a preprocessor which is a program invoked by the
{
printf("GeeksQuiz"); compiler. In a very basic term, the preprocessor takes a C
return 0; program and produces another C program. The produced
} program has no lines starting with #, all such lines are
processed by the preprocessor.
Line 2 [ int main(void) ]
#include <stdio.h>
There must be a starting point from where execution of
int main(void)
compiled C program begins. In C, the execution typically
{
printf("GeeksQuiz"); begins with the first line of main(). The void written in
return 0; brackets indicates that the main doesn’t take any
} parameter . main() can be written to take parameters also.
The int was written before main indicates return type of
main(). The value returned by main indicates the status of
program termination.
Line 3 and 6: [ { and } ]
#include <stdio.h>
In C language, a pair of curly brackets define scope and
int main(void)
are mainly used in functions and control statements like if,
{
printf("GeeksQuiz"); else, loops. All functions must start and end with curly
return 0; brackets.
}
Line 4 [ printf(“GeeksQuiz”); ]
#include <stdio.h>
printf() is a standard library function to print something on
int main(void)
standard output. The semicolon at the end of printf
{
printf("GeeksQuiz"); indicates line termination. In C, a semicolon is always
return 0; used to indicate end of a statement.
}
Line 5 [ return 0; ]
#include <stdio.h>
The return statement returns the value from main(). The
int main(void)
returned value may be used by an operating system to
{
printf("GeeksQuiz"); know the termination status of your program. The value 0
return 0; typically means successful termination.
}
Understanding some basic
terminologies in programming
IDE - An integrated development environment (IDE) is a software
application that provides comprehensive facilities to
computer programmers .

EXAMPLES OF IDE SUGGESTED IDE FOR C Language


Understanding some basic
terminologies in programming
COMPILE - Compiling is the transformation
from Source Code (human readable) into
machine code (computer executable). A
compiler is a program. A compiler takes the
recipe (code) for a new program (written in a
high level language) and transforms this Code
into a new language (Machine Language) that
can be understood by the computer itself.
Understanding some basic
terminologies in programming
Debugging - is a methodical process of finding and reducing the number of bugs
(or defects) in a computer program, thus making it behave as originally expected.

Syntax Error - a syntax error is an error in the syntax of a sequence of characters or tokens
that is intended to be written in a particular programming language.

Syntax - Syntax refers to the rules that define the structure of a language. Syntax in computer
programming means the rules that control the structure of the symbols, punctuation, and words
of a programming language.

Example of Syntax in C:

Display a message:
printf(“Put your Message Here”);
SCENARIO:
SAMPLE PROGRAM THAT PRINTS HELLO WORLD:
NOW LET US APPLY THE PREVIOUS TOPIC WE DISCUSS

FLOWCHART PSEUDOCODE CODE

#include<stdio.h>
START Step 1: Start main()
{
Step 2: Display Hello World printf(“Hello
Display World”);
“Hello World”
Step 3: Stop }
Output:
End Hello World
ESCAPE SEQUENCE IN C
An escape sequence is a sequence of characters used in formatting
the output and are not displayed while printing text on to the
screen, each having its own specific function.

1.\n (New line) – We use it to shift the cursor control to the new line
2.\t (Horizontal tab) – We use it to shift the cursor to a couple of spaces to the right in the
same line.
3.\r (Carriage Return) – We use it to position the cursor to the beginning of the current line.
4.\\ (Backslash) – We use it to display the backslash character.
5.\’ (Apostrophe or single quotation mark) – We use it to display the single-quotation mark.
6.\” (Double quotation mark)- We use it to display the double-quotation mark.
7.\0 (Null character) – We use it to represent the termination of the string.
8.\? (Question mark) – We use it to display the question mark. (?)
9.\nnn (Octal number)- We use it to represent an octal number.
10.\xhh (Hexadecimal number) – We use it to represent a hexadecimal number.
11.\v (Vertical tab)
12.\b (Backspace)
13.\e (Escape character)
14.\f (Form Feed page break)
print(“Biliran\n”);
print(“Province\n”);
print(“State\n”);
print(“University\n”);
MAKE A FLOWCHART, PSEUDOCODE, CODE AND OUTPUT OF THE
FOLLOWING SCENARIOSi:

1. Create a Program that display your Name, Age, Address and your Favorite pet.
2. Create a program that display this output:

3. Create a program that display this output:

*
* *
* * *
* * * *
* * * **
* * * ***
* * * ****
Submit your output in Google Classroom
Deadline is until 10pm only
Always include your name at the end of the program:
SAMPLE OUTPUT

1. Scenario: Create A PROGRAM THAT PRINTS HELLO WORLD:


NOW LET US APPLY THE PREVIOUS TOPIC WE DISCUSS

FLOWCHART PSEUDOCODE CODE

#include<stdio.h>
START Step 1: Start main()
{
Step 2: Display Hello World printf(“Hello
Display World”);
“Hello World”
Step 3: Stop printf(“Submitted by:
Jonicio Dacuya”)
} Output:
End
Screenshot Hello World

You might also like