SlideShare a Scribd company logo
What is C
C is a programming language created by Dennis Ritchie at Bell Labs in the 1970s. It's important
because many well-known operating systems like Unix, Microsoft Windows, Mac OS X, and
GNU/Linux are written in C.
Besides operating systems, many other popular programming languages like Perl, PHP, Python, R,
Matlab, and Mathematica are based on or influenced by C.
As of July 2012, C has been ranked as the most popular programming language according to the
TIOBE index - a well known website which ranks the programming langauages. This shows that C is
trusted by many programmers and is still widely used today.
Introduction
Let us output an integer in C.
C has a few lines of code which we write in almost all programs.
These are the first 2 lines that you see in the program to your right. We are going to learn about
them in some time.
#include <stdio.h>
int main() {
printf("%d", 12);
}
For now, read the Line 5: "printf("%d", 12);"
Let's break down this line of code:
1. printf: This is a function in C used for printing or displaying information on the screen.
2. "%d": This is a format specifier. It tells printf how to interpret the data it's given. In this
case, %d is used for integers (whole numbers).
3. 12: This is the actual data you want to print. Here, it's the number 12.
So, when you write printf("%d", 12);, it tells the computer to print the integer 12 on the screen.
Note that this line contains a (;) semicolon at the end. Semicolon is mandatory at the end of
statements in C.
We'll talk about the first line of code #include<stdio.h> soon.
Printing a number
In the last problem we saw how to print a number. Now it's your turn to print another number.
Your task is to print the number 20 on the screen.
In the editor, we have written some code for you. But instead of number 20, __ (underscores) are written.
Delete those underscores and write 20 at that place to complete the code.
#include <stdio.h>
int main() {
// Delete __ (underscore) and add 20 at it's place
printf("%d", __);
}
Arithmetic Operations
We can also perform mathematical operations (like addition, subtraction etc) with printf().
These use the familiar symbols of:
+ => + for addition
− => − for subtraction
∗ => ∗ for multiplication
/ => / for division
To add two number we do this:
printf("%d", 21 + 40);
The above line of code will output: 61
Again, printf is the function we use when we want to print. "%d" tells the compiler that we want to
print a number. And writing 21 + 40 tells the compiler to add these two number and print the sum.
Task
Try to add 21 and 40 in code and print the result. Remember, we don't need "" (double quotes) when
printing numbers.
#include <stdio.h>
int main() {
// Replace the underscores
printf(___);
}
Comments
In last section, you might have noticed this symbol // and some text instruction in the code editor.
That was a comment.
Comments in C are notes added to code to explain what the code does or any other kind of
information about the code. They are helpful for making the code easier to understand.
Types of Comments in C
In C, there are two primary ways to add comments to your code:
Single-Line Comments:
Syntax: // Your comment here
Example:
int main() {
printf("%d", 12); // This is a single-line comment. the printf statement prints 12.
}
Single-line comments start with // and continue to the end of the line. They are useful for adding
brief explanations or notes about specific lines of code.
Multi-Line Comments:
Syntax: /* Your multi-line comment here */
Example:
/*
This is a multi-line comment
spanning multiple lines
*/
int main() {
printf("%d", 12);
}
Multi-line comments start with /* and end with */. They can span multiple lines and are typically
used for longer explanations or for commenting out large blocks of code.
Best Practices for Using Comments in C
Be Descriptive: Always strive to write clear and descriptive comments that explain the purpose,
functionality, or reasoning behind the code.
Update Regularly: Remember to update comments when you modify the code to ensure they
remain accurate and relevant.
Avoid Redundancy: Avoid writing comments that only restate the obvious. Comments should
provide additional information or insights that are not immediately evident from the code itself.
Printing text
In the last problem, we saw how to print a number(using printf()).
To print a number we write this:
printf("%d", 42);
But to output a text, we do this
printf("I love C");
This will print I love C to the screen. No need to add any %d or anything. Just the text you want to
print inside quotes ("").
Task
Replace the __ (underscores) in the editor with the text "I love C" to output I love C.
#include <stdio.h>
int main() {
// Replace the _ (underscores) with the correct value
printf("__");
}
Which line of code will output the sum of 7 and 19?
a) Printf(7 + 19)
b) printf("%d",7 + 19);
c) printf("7 + 19");
d) printf(%d,7 + 19);
Task
Write a program which does the following
 Add a printf statement and output the sum of 3 + 4
 Add another printf statement and output the sum of 2 + 1.
Use the printf syntax we learned in last problem.
Note - Notice that in the output they are printed together without any space between them.
Expected Output
73
Review and Reflect - Print
In this lesson, we learned about how to output numbers and text in C using print statement.
To print numbers, we just add them inside print, along with format specifier:
printf("%d", 21);
// Output:
// 21
Don't forget the semicolon (;) at the end of line.
Also, we can do mathematical operations inside print statement itself, like addition, subtraction etc.
printf("%d", 2 + 2);
printf("%d", 1 - 2);
// Output:
// 4
// -1
To print text, we use double quotes:
printf("I am learning C");
// Output:
// I am learning C
You get an error if you write any of the syntax incorrectly. Be careful when writing code, because
machines need very exact instructions.
Also, as mentioned previously, any text that start with // is called a comment and C compiler ignores these
lines when running your code.
In the next lesson, we will learn about how we can use print statement to print on multiple lines or multiple
texts on same line, and do more complex mathematical operations.
Outputs In Separate Lines
When we use multiple printf statements, everything gets printed on one line.
printf("%d", 20);
printf("%d", 40);
// Output:
// 2040
What to do if we want to print 20 and 40 on separate lines?
We can use "n" to have the next outputs be on the next line. It is like pressing
the "Enter" / "Return" key on your keyboard, but for the output displayed.
Example:
printf("%dn", 20);
printf("%dn", 40);
// Output:
// 20
// 40
Task
Write a program which does the following
 Output the sum of 3 and 4 using printf.
 Output the sum of 1 and 2 using printf, but on a new line.
Expected Output
7
3
Area & Perimeter of Rectangle
Write a program for the following problem
 Let’s consider a rectangle of sides 1111 and 1313.
 Find and output area of the rectangle having sides as 1111 and 1313
 Find and output perimeter of the rectangle having side as 1111 and 1313
For any rectangle, the formula for area is length * breadth.
The formula for perimeter is 2 * (length + breadth).
Expected output
143
48
#include <stdio.h>
int main() {
// Add the formula for area of 11 and 13
printf("%dn", _____);
// Add the formula for perimeter of 11 and 13
printf("%dn", _ * (_____));
}

More Related Content

Similar to What is C Programming LAnguage and Why to Learn.docx (20)

PPTX
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
ssuser71a90c
 
PPTX
C Programming Unit-1
Vikram Nandini
 
PPTX
c_pro_introduction.pptx
RohitRaj744272
 
PDF
C Language Lecture 2
Shahzaib Ajmal
 
PPTX
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
PDF
88 c-programs
Leandro Schenone
 
PPTX
1.1 programming fundamentals
Jawad Khan
 
PPT
CHTP5e_02.ppt jkkkkkkk jjj
faiqa81
 
PPTX
Introduction to C Programming language Chapter02.pptx
foxel54542
 
PPTX
Cpu
Mohit Jain
 
PPT
Lập trình C
Viet NguyenHoang
 
PPTX
What is c
Nitesh Saitwal
 
PPT
270_1_ChapterIntro_Up_To_Functions (1).ppt
GayathriShiva4
 
PPTX
C language (1).pptxC language (1C language (1).pptx).pptx
RutviBaraiya
 
PPTX
Programming basics
illidari
 
DOCX
C language industrial training report
Raushan Pandey
 
PPTX
C Programming - Basics of c -history of c
DHIVYAB17
 
PPTX
Introduction to C Programming
Aniket Patne
 
PPT
Survey of programming language getting started in C
ummeafruz
 
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
ssuser71a90c
 
C Programming Unit-1
Vikram Nandini
 
c_pro_introduction.pptx
RohitRaj744272
 
C Language Lecture 2
Shahzaib Ajmal
 
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
88 c-programs
Leandro Schenone
 
1.1 programming fundamentals
Jawad Khan
 
CHTP5e_02.ppt jkkkkkkk jjj
faiqa81
 
Introduction to C Programming language Chapter02.pptx
foxel54542
 
Lập trình C
Viet NguyenHoang
 
What is c
Nitesh Saitwal
 
270_1_ChapterIntro_Up_To_Functions (1).ppt
GayathriShiva4
 
C language (1).pptxC language (1C language (1).pptx).pptx
RutviBaraiya
 
Programming basics
illidari
 
C language industrial training report
Raushan Pandey
 
C Programming - Basics of c -history of c
DHIVYAB17
 
Introduction to C Programming
Aniket Patne
 
Survey of programming language getting started in C
ummeafruz
 

Recently uploaded (20)

PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PDF
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
PPTX
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
PDF
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
PPT
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
PDF
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
PPTX
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
PPTX
Photo chemistry Power Point Presentation
mprpgcwa2024
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
PPTX
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
PPTX
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
PDF
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
PPTX
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
How to use grouped() method in Odoo 18 - Odoo Slides
Celine George
 
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
Photo chemistry Power Point Presentation
mprpgcwa2024
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
Ad

What is C Programming LAnguage and Why to Learn.docx

  • 1. What is C C is a programming language created by Dennis Ritchie at Bell Labs in the 1970s. It's important because many well-known operating systems like Unix, Microsoft Windows, Mac OS X, and GNU/Linux are written in C. Besides operating systems, many other popular programming languages like Perl, PHP, Python, R, Matlab, and Mathematica are based on or influenced by C. As of July 2012, C has been ranked as the most popular programming language according to the TIOBE index - a well known website which ranks the programming langauages. This shows that C is trusted by many programmers and is still widely used today.
  • 2. Introduction Let us output an integer in C. C has a few lines of code which we write in almost all programs. These are the first 2 lines that you see in the program to your right. We are going to learn about them in some time. #include <stdio.h> int main() { printf("%d", 12); } For now, read the Line 5: "printf("%d", 12);" Let's break down this line of code: 1. printf: This is a function in C used for printing or displaying information on the screen. 2. "%d": This is a format specifier. It tells printf how to interpret the data it's given. In this case, %d is used for integers (whole numbers). 3. 12: This is the actual data you want to print. Here, it's the number 12. So, when you write printf("%d", 12);, it tells the computer to print the integer 12 on the screen. Note that this line contains a (;) semicolon at the end. Semicolon is mandatory at the end of statements in C. We'll talk about the first line of code #include<stdio.h> soon.
  • 3. Printing a number In the last problem we saw how to print a number. Now it's your turn to print another number. Your task is to print the number 20 on the screen. In the editor, we have written some code for you. But instead of number 20, __ (underscores) are written. Delete those underscores and write 20 at that place to complete the code. #include <stdio.h> int main() { // Delete __ (underscore) and add 20 at it's place printf("%d", __); } Arithmetic Operations We can also perform mathematical operations (like addition, subtraction etc) with printf(). These use the familiar symbols of: + => + for addition − => − for subtraction ∗ => ∗ for multiplication / => / for division To add two number we do this: printf("%d", 21 + 40); The above line of code will output: 61 Again, printf is the function we use when we want to print. "%d" tells the compiler that we want to print a number. And writing 21 + 40 tells the compiler to add these two number and print the sum. Task Try to add 21 and 40 in code and print the result. Remember, we don't need "" (double quotes) when printing numbers. #include <stdio.h> int main() { // Replace the underscores printf(___); }
  • 4. Comments In last section, you might have noticed this symbol // and some text instruction in the code editor. That was a comment. Comments in C are notes added to code to explain what the code does or any other kind of information about the code. They are helpful for making the code easier to understand. Types of Comments in C In C, there are two primary ways to add comments to your code: Single-Line Comments: Syntax: // Your comment here Example: int main() { printf("%d", 12); // This is a single-line comment. the printf statement prints 12. } Single-line comments start with // and continue to the end of the line. They are useful for adding brief explanations or notes about specific lines of code. Multi-Line Comments: Syntax: /* Your multi-line comment here */ Example: /* This is a multi-line comment spanning multiple lines */ int main() { printf("%d", 12); } Multi-line comments start with /* and end with */. They can span multiple lines and are typically used for longer explanations or for commenting out large blocks of code. Best Practices for Using Comments in C Be Descriptive: Always strive to write clear and descriptive comments that explain the purpose, functionality, or reasoning behind the code. Update Regularly: Remember to update comments when you modify the code to ensure they remain accurate and relevant. Avoid Redundancy: Avoid writing comments that only restate the obvious. Comments should provide additional information or insights that are not immediately evident from the code itself.
  • 5. Printing text In the last problem, we saw how to print a number(using printf()). To print a number we write this: printf("%d", 42); But to output a text, we do this printf("I love C"); This will print I love C to the screen. No need to add any %d or anything. Just the text you want to print inside quotes (""). Task Replace the __ (underscores) in the editor with the text "I love C" to output I love C. #include <stdio.h> int main() { // Replace the _ (underscores) with the correct value printf("__"); } Which line of code will output the sum of 7 and 19? a) Printf(7 + 19) b) printf("%d",7 + 19); c) printf("7 + 19"); d) printf(%d,7 + 19); Task Write a program which does the following  Add a printf statement and output the sum of 3 + 4  Add another printf statement and output the sum of 2 + 1. Use the printf syntax we learned in last problem. Note - Notice that in the output they are printed together without any space between them. Expected Output 73
  • 6. Review and Reflect - Print In this lesson, we learned about how to output numbers and text in C using print statement. To print numbers, we just add them inside print, along with format specifier: printf("%d", 21); // Output: // 21 Don't forget the semicolon (;) at the end of line. Also, we can do mathematical operations inside print statement itself, like addition, subtraction etc. printf("%d", 2 + 2); printf("%d", 1 - 2); // Output: // 4 // -1 To print text, we use double quotes: printf("I am learning C"); // Output: // I am learning C You get an error if you write any of the syntax incorrectly. Be careful when writing code, because machines need very exact instructions. Also, as mentioned previously, any text that start with // is called a comment and C compiler ignores these lines when running your code. In the next lesson, we will learn about how we can use print statement to print on multiple lines or multiple texts on same line, and do more complex mathematical operations.
  • 7. Outputs In Separate Lines When we use multiple printf statements, everything gets printed on one line. printf("%d", 20); printf("%d", 40); // Output: // 2040 What to do if we want to print 20 and 40 on separate lines? We can use "n" to have the next outputs be on the next line. It is like pressing the "Enter" / "Return" key on your keyboard, but for the output displayed. Example: printf("%dn", 20); printf("%dn", 40); // Output: // 20 // 40 Task Write a program which does the following  Output the sum of 3 and 4 using printf.  Output the sum of 1 and 2 using printf, but on a new line. Expected Output 7 3 Area & Perimeter of Rectangle Write a program for the following problem  Let’s consider a rectangle of sides 1111 and 1313.  Find and output area of the rectangle having sides as 1111 and 1313  Find and output perimeter of the rectangle having side as 1111 and 1313 For any rectangle, the formula for area is length * breadth. The formula for perimeter is 2 * (length + breadth). Expected output 143
  • 8. 48 #include <stdio.h> int main() { // Add the formula for area of 11 and 13 printf("%dn", _____); // Add the formula for perimeter of 11 and 13 printf("%dn", _ * (_____)); }