SlideShare a Scribd company logo
1 of 11
Download to read offline
Examination preparation of C written by – Md. Shahariar Sarkar.
Introducton to C Chapter
Basic I/O 1
What is C language?
C programming language is a general-purpose, high-level language .It was originally developed
by Dennis M. Ritchie to develop the UNIX operating system at bell Laboratory in 1971. C was
originally first implemented on the DEC PDP-11 computer in 1972.
The UNIX OS was totally written in C by 1973. In 1978, Brian Kernighan and Dennis Ritchie
produced the first publicly available description of C, now known as the K&R standard. After
that the language was formalized in 1988 by the American National Standard Institute. (ANSI)
and its known as ANSI standard.
As the successor of B language, it was named as C language.
Why C is more popular?
C has become more popular because of the following reasons.
 It is easy to learn.
 It is a structured language.
 It produces efficient program.
 It can handle low level activities.
 It can be compiled on a variety of computer platforms.
Where, C is used?
C is the most widely used programming language in the world for its high power productivity. It
is used in different field of computer such as.
 Operating system Windows, UNIX, LINUX
 Application software such as Word, Excel, Foxpro etc.
 Programming language such as Java, Visual basic etc all are the products of C.
 Print spoolers.
 Network Drivers.
 Database Management System (DBMS) - MySQL is written by C.
Examination preparation of C written by – Md. Shahariar Sarkar.
Structure of a C program:
Include header file section.
Global declaration section.
main()
{
Definition of the function.
}
User-defined functions
{
Definition of the function.
}
Examination preparation of C written by – Md. Shahariar Sarkar.
Example of Rule -1.
1.Write a program that print the following sentence
Hello world ! I am a programmar
#include<stdio.h>
int main()
{
printf(“Hello world ! I am a programmar”);
return 0;
}
2. write a program that print the following sentence
in two line.
Hello world !
I am a programmar.
#include<stdio.h>
int main()
{
printf(“Hello world n”);
printf(“I am a programmar”);
return 0;
}
Here, n –new line
Now,t- tab
a-alert bell.
v- vertically distance.
What is header file of C?
Header file is a file of C library that
contains the declarations and definition
of library function.
Ex-stdio.h is the header file that
contains the declarations and definition
for certain input or output functions
such as printf, scanf etc.
What is function? How many types
of function. Define and give
exmaple.
A function is a well-defined program
segment that performs some specific
tasks.
There are two types of function in C.
i)Library function / Built- in function.
ii)User defined function.
Library function/Built-in function:
The functions whose name and syntax
are predefined that can not be changed
by the programmer are called Built-in
function. They are also called library
functions because the definition of
these functions are stored in the header
files of C library.
Ex: printf(), scanf() etc.
User-defined function:
The function that is defined by the user
is called user defined function. Using
defferent library functions, a
programmer makes user defined
function.
Ex- main() function is an user defined
function.
Rule-1: If we want to print any sentence
/word by C language then we have to
write-
printf(“ Sentence”);
Examination preparation of C written by – Md. Shahariar Sarkar.
3. Write the program no.2 using the t, v, a.
#inlcude<stdio.h>
int main()
{
printf(“tHello world”);
return 0;
}
Examination preparation of C written by – Md. Shahariar Sarkar.
Rule-2. If any arithmetic
number/charcter is needed to a
program then a variable has to be
declared.
Variable declaration-
data_type variable_name;
Example: int num;
For multiple variables
data_type variable1, variable2;
float value;
Data type
name
Data type Size
(byte)
Range Format
Specifier
Character
char
1 -27
to
27
-1 %c
Unsigned
Character
unsigned
char
1 0 to 27
%c
Integer int 2/4
-215
to
215
-1
%d
Long long
4
-231 to
231
-1
%ld
Float float
4
1.7e – 308
to 1.7e+30
8 %f
Double double
8
3.4e – 493
2 to 1.1e+4
932 %lf
Long
Double
Long double
10
3.4e – 493
2
to 1.1e+49
32
%lf
Make a table for all data types of C.
Rule-4. If we want to print the value
of a variable then we have to write-
printf(“specifier”, variable_name);
Rule-3. If we want to give the value of
a variable as an input (from keyboard
to screen) then we have to write-
scanf(“specifier” ,&variable_name);
Examination preparation of C written by – Md. Shahariar Sarkar.
Examples of rule-2,3and 4:
4. Write a program that takes
two integer number and
calculate the addition.
#include<stdio.h>
int main()
{
int a, b,sum;
scanf(“%d %d”,&a,&b);
sum=a+b;
printf(“%d”,sum);
return 0;
}
5. Write a program that take the
radius of a circle as an input and
calculate the area of the circle.
#include<stdio.h>
int main()
{
double r, area;
scanf(“%lf ” , &r);
area=3.1416*r*r;
printf(“ %lf ” , area);
return 0;
}
What is C token? Classify and briefly describe them?
In C language, Every meaningful individual unit is called C
token.
C has six types of tokens-
1. Keywords/reserved words.
2. Identifier.
3. Constants.
4. Strings.
5. Special Symbols.
6. Operators.
Keywords/reserved words:
In c language, some words have specific meaning that cannot
be changed, are called keywords or reserved words.
Example- auto, break, while, for, main, if, else etc.
Identifiers:
Identifiers are the name of variables, functions and arrays. They
are user-defined name.
Example- int num;
Here, num is a variable identifirer.
Constans:
The fixed values that cannot change during execution of the
program are called constants.
Example: int a=10;
Here, 10 is constant.
Strings:
The words that are written between double quotations are called
strings.
Ex- printf(“Hello world”);
Here, ‘Hello world’ is a string.
Examination preparation of C written by – Md. Shahariar Sarkar.
6. Write a program that
calculate the area of a rectangle.
#include<stdio.h>
int main()
{
int height,width,area.
printf(“ Please Enter height”);
scanf(“%d” , &height);
printf(“Please Enter width”);
scanf(“%d”, &width);
area=height*width;
printf(“The area= %d” , area);
return 0;
}
7. Write a program that takes
three integer numbers and
interchange them.
#include<stdio.h>
int main()
{
int a,b,c, temp;
printf(“Please Enter numbers”);
scanf(“%d %d %d”,&a,&b,&c);
temp=a;
a=b;
b=c;
c=temp;
printf(“%d %d %d”,a,b,c);
return 0;}
Special symbols:
In C language, different types of special symbols are used.
Ex- {}; ( ); $ etc.
Operator:
There are different types of operator in C language such that +;
-; && etc.
Write the Classification of operator with example.
There are different types of operator in C as follows-
Type of Operator Symbolic representation
Arithmetic operators +, -, *, /, %
Relational operators >, <, ==, >=, <=, !=
Logical operators &&(AND), ||(OR), !(NOT)
Increment and decrement operator ++ , --
Assignment operator =
Bitwise operator &, |, ^, >>, <<, ~
Comma operator ,
Conditional operator ?:
Examination preparation of C written by – Md. Shahariar Sarkar.
8. Write a program to calculate
the area of any triangle.
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c;
float s,area;
printf("Enter size of each sides of
triangle");
scanf("%f %f %f",&a,&b,&c);
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle is:
%.3f",area);
return 0;
}
a c
b
Formula of area of any triangle:
Area = √(s*(s-a)*(s-b)*(s-c))
Where s = (a + b + c)/2
sqrt() →√
What is variable? How many types of variable? Write the
convention to write a variable in C.
Variable: A variable is an identifier that can hold a single value
and it can be changed. When a variable is declared its allocate a
memory space according to its data type.
Depending of declaration place in the program, variable can be
classified into two categories-
1. Local variable
2. Global variable.
Local variable: The variable which is declared inside a function
and it cannot be accessed by other function is called Local
variable.
Example:
#include<stdio.h>
int main()
{
int value;
}
Here value is a local variable of main() function.
Global Variable: The variable which is declared outside of all
function and all function can access that variable is called
Global variable.
Exaple:
#include<stdio.h>
int mark;
int count()
{
……………….
……………….
}
Examination preparation of C written by – Md. Shahariar Sarkar.
9. Write a program to calculate
the area of a right angled triangle.
#include<stdio.h>
int main(){
float h,w;
float area;
printf("Enter height and width of
the right angled triangle : ");
scanf("%f%f",&h,&w);
area = 0.5 * h * w;
printf("Area of right angled triangle
is: %.3f",area);
return 0;
}
10. Write a program to calculate
the area and volume of sphere.
#include<stdio.h>
#include<math.h>
int main(){
float r;
float surface_area,volume;
printf("Enter radius of the sphere :
");
scanf("%f",&r);
surface_area = 4* 3.14 * r * r;
volume = (4/3) * 3.14 * r * r * r;
printf("Surface area of sphere is:
%.3f",surface_area);
printf("nVolume of sphere is :
%.3f",volume);
return 0;
}
int main()
{
……………….
………………..
}
Here mark is global variable, in this case, count() and main()
both function can use the variable mark.
Convention to write the name of a variable or identifier:
1. First character must be an alphabet or underscore.
2. Must be consist of only letters, digits or underscore.
3. Only first 31 characters are significant.
4. Keyword cannot be used.
5. Must not contain white space.
What are different storage class? Briefly describe.
Storage class: A storage class defines the scope and life- time of
variables or function within a C program.
There following storage classes, which can be used in C
program-
1. auto
2. register
3. static
4. extern
Auto storage class: Auto storage class is a default storage class
for all local variables. The compiler allocates separate memory
for each automatic (auto) variable of different functions, even if
they have the same name. Use auto specifier make a variable
automatic. If there is no specifier before variable then also the
compiler treat it as an automatic variable.
int main()
{
int count;
auto int month;
}
Examination preparation of C written by – Md. Shahariar Sarkar.
Register storage class: Register storage class is used to allocate
space of a variable in a register instead of RAM.
It can't have the unary '&' operator applied to it (as it does not
have a memory location).
Example:
int main()
{
register int miles;
scanf(“%d” , miles);
}
Static storage class: When a local variable is declared as static,
the compiler allocates a permanent memory space for that
variable and when a global variable is declared as static it is
known only by its own file, so it cannot be accessed by other
file.
void addition()
{
static int a;
}
Extern storage class: When a variable is needed to use in a file
that is declared later in that file or another file then extern
storage class is used.
void main()
{
extern int a, b;
printf(“%d %d”, a,b);
}
int a=10, b=20;
Examination preparation of C written by – Md. Shahariar Sarkar.
Exercise:
1. Write a program to transform the temperature from Celsius to Fahrenheit.
Formula: C/5= (F-32)/9.
2. Write the program using the following library functions
pow(a,b)=ab
abs(-a)=a [Finds absolute value of integer]
cos(ϴ)→Finds the cosine value.
sin(ϴ)→Finds the sine value.
tan(ϴ)→Finds the tangent value.
sqrt(a)→√a.
toascii(a)→Finds ASCII value.
tolower(a)→Finds lower case.
toupper(a)-Finds Upper case.
Sample answer of question: 2
#include<stdio.h>
int main()
{
char a;
scanf("%c",&a);
printf("%c",toupper(a));
return 0;
}

More Related Content

What's hot (20)

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
20 C programs
20 C programs20 C programs
20 C programs
 
C Programming
C ProgrammingC Programming
C Programming
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
C program
C programC program
C program
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
C language basics
C language basicsC language basics
C language basics
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
 

Viewers also liked

Viewers also liked (20)

Data structures 4
Data structures 4Data structures 4
Data structures 4
 
lecture 9
lecture 9lecture 9
lecture 9
 
Lists
ListsLists
Lists
 
Sorting1
Sorting1Sorting1
Sorting1
 
Cis435 week06
Cis435 week06Cis435 week06
Cis435 week06
 
Nikit
NikitNikit
Nikit
 
Chapter 8 sorting algo
Chapter 8 sorting algoChapter 8 sorting algo
Chapter 8 sorting algo
 
Data structure
 Data structure Data structure
Data structure
 
Linear time sorting algorithms
Linear time sorting algorithmsLinear time sorting algorithms
Linear time sorting algorithms
 
Cs105 l15-bucket radix
Cs105 l15-bucket radixCs105 l15-bucket radix
Cs105 l15-bucket radix
 
Shell sort
Shell sortShell sort
Shell sort
 
Sample chapters [data structure and algorithmic thinking with python]
Sample chapters [data structure and algorithmic thinking with python]Sample chapters [data structure and algorithmic thinking with python]
Sample chapters [data structure and algorithmic thinking with python]
 
Algorithms presentation on Path Matrix, Bell Number and Sorting
Algorithms presentation on Path Matrix, Bell Number and SortingAlgorithms presentation on Path Matrix, Bell Number and Sorting
Algorithms presentation on Path Matrix, Bell Number and Sorting
 
Data structures and algorithm
Data structures and algorithmData structures and algorithm
Data structures and algorithm
 
Sorting Seminar Presentation by Ashin Guha Majumder
Sorting Seminar Presentation by Ashin Guha MajumderSorting Seminar Presentation by Ashin Guha Majumder
Sorting Seminar Presentation by Ashin Guha Majumder
 
SORTTING IN LINEAR TIME - Radix Sort
SORTTING IN LINEAR TIME - Radix SortSORTTING IN LINEAR TIME - Radix Sort
SORTTING IN LINEAR TIME - Radix Sort
 
3.3 shell sort
3.3 shell sort3.3 shell sort
3.3 shell sort
 
Shell sort
Shell sortShell sort
Shell sort
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
BUCKET SORT
BUCKET SORTBUCKET SORT
BUCKET SORT
 

Similar to C programming

Similar to C programming (20)

Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
C programming
C programmingC programming
C programming
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Basic c
Basic cBasic c
Basic c
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Basics of C porgramming
Basics of C porgrammingBasics of C porgramming
Basics of C porgramming
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 

C programming

  • 1. Examination preparation of C written by – Md. Shahariar Sarkar. Introducton to C Chapter Basic I/O 1 What is C language? C programming language is a general-purpose, high-level language .It was originally developed by Dennis M. Ritchie to develop the UNIX operating system at bell Laboratory in 1971. C was originally first implemented on the DEC PDP-11 computer in 1972. The UNIX OS was totally written in C by 1973. In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. After that the language was formalized in 1988 by the American National Standard Institute. (ANSI) and its known as ANSI standard. As the successor of B language, it was named as C language. Why C is more popular? C has become more popular because of the following reasons.  It is easy to learn.  It is a structured language.  It produces efficient program.  It can handle low level activities.  It can be compiled on a variety of computer platforms. Where, C is used? C is the most widely used programming language in the world for its high power productivity. It is used in different field of computer such as.  Operating system Windows, UNIX, LINUX  Application software such as Word, Excel, Foxpro etc.  Programming language such as Java, Visual basic etc all are the products of C.  Print spoolers.  Network Drivers.  Database Management System (DBMS) - MySQL is written by C.
  • 2. Examination preparation of C written by – Md. Shahariar Sarkar. Structure of a C program: Include header file section. Global declaration section. main() { Definition of the function. } User-defined functions { Definition of the function. }
  • 3. Examination preparation of C written by – Md. Shahariar Sarkar. Example of Rule -1. 1.Write a program that print the following sentence Hello world ! I am a programmar #include<stdio.h> int main() { printf(“Hello world ! I am a programmar”); return 0; } 2. write a program that print the following sentence in two line. Hello world ! I am a programmar. #include<stdio.h> int main() { printf(“Hello world n”); printf(“I am a programmar”); return 0; } Here, n –new line Now,t- tab a-alert bell. v- vertically distance. What is header file of C? Header file is a file of C library that contains the declarations and definition of library function. Ex-stdio.h is the header file that contains the declarations and definition for certain input or output functions such as printf, scanf etc. What is function? How many types of function. Define and give exmaple. A function is a well-defined program segment that performs some specific tasks. There are two types of function in C. i)Library function / Built- in function. ii)User defined function. Library function/Built-in function: The functions whose name and syntax are predefined that can not be changed by the programmer are called Built-in function. They are also called library functions because the definition of these functions are stored in the header files of C library. Ex: printf(), scanf() etc. User-defined function: The function that is defined by the user is called user defined function. Using defferent library functions, a programmer makes user defined function. Ex- main() function is an user defined function. Rule-1: If we want to print any sentence /word by C language then we have to write- printf(“ Sentence”);
  • 4. Examination preparation of C written by – Md. Shahariar Sarkar. 3. Write the program no.2 using the t, v, a. #inlcude<stdio.h> int main() { printf(“tHello world”); return 0; }
  • 5. Examination preparation of C written by – Md. Shahariar Sarkar. Rule-2. If any arithmetic number/charcter is needed to a program then a variable has to be declared. Variable declaration- data_type variable_name; Example: int num; For multiple variables data_type variable1, variable2; float value; Data type name Data type Size (byte) Range Format Specifier Character char 1 -27 to 27 -1 %c Unsigned Character unsigned char 1 0 to 27 %c Integer int 2/4 -215 to 215 -1 %d Long long 4 -231 to 231 -1 %ld Float float 4 1.7e – 308 to 1.7e+30 8 %f Double double 8 3.4e – 493 2 to 1.1e+4 932 %lf Long Double Long double 10 3.4e – 493 2 to 1.1e+49 32 %lf Make a table for all data types of C. Rule-4. If we want to print the value of a variable then we have to write- printf(“specifier”, variable_name); Rule-3. If we want to give the value of a variable as an input (from keyboard to screen) then we have to write- scanf(“specifier” ,&variable_name);
  • 6. Examination preparation of C written by – Md. Shahariar Sarkar. Examples of rule-2,3and 4: 4. Write a program that takes two integer number and calculate the addition. #include<stdio.h> int main() { int a, b,sum; scanf(“%d %d”,&a,&b); sum=a+b; printf(“%d”,sum); return 0; } 5. Write a program that take the radius of a circle as an input and calculate the area of the circle. #include<stdio.h> int main() { double r, area; scanf(“%lf ” , &r); area=3.1416*r*r; printf(“ %lf ” , area); return 0; } What is C token? Classify and briefly describe them? In C language, Every meaningful individual unit is called C token. C has six types of tokens- 1. Keywords/reserved words. 2. Identifier. 3. Constants. 4. Strings. 5. Special Symbols. 6. Operators. Keywords/reserved words: In c language, some words have specific meaning that cannot be changed, are called keywords or reserved words. Example- auto, break, while, for, main, if, else etc. Identifiers: Identifiers are the name of variables, functions and arrays. They are user-defined name. Example- int num; Here, num is a variable identifirer. Constans: The fixed values that cannot change during execution of the program are called constants. Example: int a=10; Here, 10 is constant. Strings: The words that are written between double quotations are called strings. Ex- printf(“Hello world”); Here, ‘Hello world’ is a string.
  • 7. Examination preparation of C written by – Md. Shahariar Sarkar. 6. Write a program that calculate the area of a rectangle. #include<stdio.h> int main() { int height,width,area. printf(“ Please Enter height”); scanf(“%d” , &height); printf(“Please Enter width”); scanf(“%d”, &width); area=height*width; printf(“The area= %d” , area); return 0; } 7. Write a program that takes three integer numbers and interchange them. #include<stdio.h> int main() { int a,b,c, temp; printf(“Please Enter numbers”); scanf(“%d %d %d”,&a,&b,&c); temp=a; a=b; b=c; c=temp; printf(“%d %d %d”,a,b,c); return 0;} Special symbols: In C language, different types of special symbols are used. Ex- {}; ( ); $ etc. Operator: There are different types of operator in C language such that +; -; && etc. Write the Classification of operator with example. There are different types of operator in C as follows- Type of Operator Symbolic representation Arithmetic operators +, -, *, /, % Relational operators >, <, ==, >=, <=, != Logical operators &&(AND), ||(OR), !(NOT) Increment and decrement operator ++ , -- Assignment operator = Bitwise operator &, |, ^, >>, <<, ~ Comma operator , Conditional operator ?:
  • 8. Examination preparation of C written by – Md. Shahariar Sarkar. 8. Write a program to calculate the area of any triangle. #include<stdio.h> #include<math.h> int main(){ float a,b,c; float s,area; printf("Enter size of each sides of triangle"); scanf("%f %f %f",&a,&b,&c); s = (a+b+c)/2; area = sqrt(s*(s-a)*(s-b)*(s-c)); printf("Area of triangle is: %.3f",area); return 0; } a c b Formula of area of any triangle: Area = √(s*(s-a)*(s-b)*(s-c)) Where s = (a + b + c)/2 sqrt() →√ What is variable? How many types of variable? Write the convention to write a variable in C. Variable: A variable is an identifier that can hold a single value and it can be changed. When a variable is declared its allocate a memory space according to its data type. Depending of declaration place in the program, variable can be classified into two categories- 1. Local variable 2. Global variable. Local variable: The variable which is declared inside a function and it cannot be accessed by other function is called Local variable. Example: #include<stdio.h> int main() { int value; } Here value is a local variable of main() function. Global Variable: The variable which is declared outside of all function and all function can access that variable is called Global variable. Exaple: #include<stdio.h> int mark; int count() { ………………. ………………. }
  • 9. Examination preparation of C written by – Md. Shahariar Sarkar. 9. Write a program to calculate the area of a right angled triangle. #include<stdio.h> int main(){ float h,w; float area; printf("Enter height and width of the right angled triangle : "); scanf("%f%f",&h,&w); area = 0.5 * h * w; printf("Area of right angled triangle is: %.3f",area); return 0; } 10. Write a program to calculate the area and volume of sphere. #include<stdio.h> #include<math.h> int main(){ float r; float surface_area,volume; printf("Enter radius of the sphere : "); scanf("%f",&r); surface_area = 4* 3.14 * r * r; volume = (4/3) * 3.14 * r * r * r; printf("Surface area of sphere is: %.3f",surface_area); printf("nVolume of sphere is : %.3f",volume); return 0; } int main() { ………………. ……………….. } Here mark is global variable, in this case, count() and main() both function can use the variable mark. Convention to write the name of a variable or identifier: 1. First character must be an alphabet or underscore. 2. Must be consist of only letters, digits or underscore. 3. Only first 31 characters are significant. 4. Keyword cannot be used. 5. Must not contain white space. What are different storage class? Briefly describe. Storage class: A storage class defines the scope and life- time of variables or function within a C program. There following storage classes, which can be used in C program- 1. auto 2. register 3. static 4. extern Auto storage class: Auto storage class is a default storage class for all local variables. The compiler allocates separate memory for each automatic (auto) variable of different functions, even if they have the same name. Use auto specifier make a variable automatic. If there is no specifier before variable then also the compiler treat it as an automatic variable. int main() { int count; auto int month; }
  • 10. Examination preparation of C written by – Md. Shahariar Sarkar. Register storage class: Register storage class is used to allocate space of a variable in a register instead of RAM. It can't have the unary '&' operator applied to it (as it does not have a memory location). Example: int main() { register int miles; scanf(“%d” , miles); } Static storage class: When a local variable is declared as static, the compiler allocates a permanent memory space for that variable and when a global variable is declared as static it is known only by its own file, so it cannot be accessed by other file. void addition() { static int a; } Extern storage class: When a variable is needed to use in a file that is declared later in that file or another file then extern storage class is used. void main() { extern int a, b; printf(“%d %d”, a,b); } int a=10, b=20;
  • 11. Examination preparation of C written by – Md. Shahariar Sarkar. Exercise: 1. Write a program to transform the temperature from Celsius to Fahrenheit. Formula: C/5= (F-32)/9. 2. Write the program using the following library functions pow(a,b)=ab abs(-a)=a [Finds absolute value of integer] cos(ϴ)→Finds the cosine value. sin(ϴ)→Finds the sine value. tan(ϴ)→Finds the tangent value. sqrt(a)→√a. toascii(a)→Finds ASCII value. tolower(a)→Finds lower case. toupper(a)-Finds Upper case. Sample answer of question: 2 #include<stdio.h> int main() { char a; scanf("%c",&a); printf("%c",toupper(a)); return 0; }