Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Module 1 - C Program

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 95

Introduction To C Programming

Subject Code: BESCK204E

MODULE-01

1
M O D U L E -1
SYLLABUS
(1) I N D R O D U C T I O N TO C O P U T E R H A R D WA R E A N D
S O F T WA R E
1. C O M P U T E R G E N E R AT I O N
2. COMPUTER TYPES
3. BITS
4. BY T E S & WO RS
5. CPU
6. P R IMA RY M E M O RY
7. S E C O N DA RY M E M E O RY
8. P O RT S & C O N N E C T I O N S
9. I/P D E V I C E S
10. O/P D E V I C E S
11. C O M P U T E R I N A N E T WO R K
12. N E T WO R K H A R DWA R E
13. S/W B AS I C S 8
14. S/W T Y P E S .
(2) OV E RV I E W O F C :-

1. B AS I C S T R U C T U R E O F C - P RO G R A M
2. E X E C U T I N G A C - P RO G R A M
3. C O N S TA N T VA R I A B L E A N D DATA T Y P E S
4. O P E R ATO RS A N D E X P R E S S I O N.
1) C O M P U T E R G E N E R AT I O N
 1940 – 1956: First Generation – Vacuum Tubes.

 1956 – 1963: Second Generation – Transistors.


 1964 – 1971: Third Generation – Integrated
Circuits.

 1972 – 2010:Fourth Generation -Microprocessors


2) C O M P U T E R T Y P E S
 Microcomputers (personal computers)

 Minicomputers (mid-range computers)


 Mainframe computers

 Supercomputers.

 S ervers.
 Workstations.

 Information appliances.

 Embedded computers.
3) BITS
 a "bit" is atomic: the smallest unit of storage.
A bit stores just a 0 or 1. "In the computer it's
all 0's and 1's“.

 https://www.youtube.com/watch?v=Xpk67YzOn5
w 15
4) BYTES AND WORDS
5)C PU
6) P R I M A RY M E M O RY
7 ) S ECO N DARY M E M O RY
8) P O RT S A N D C O N N E C T I O N S
Computer Ports
1)Serial and Parallel port(VGA,DVI,DISPLAY ports)

2) RCA/VEDIO C O N N E C T O R P O RT S
3) H D M I port 4) U S B

5) RJ-45 6) 3.5 mm Audio Jack


C ABLE S
1. VG A Cable

2. DV I Cable
 3. H D M I Cable

 4. Ethernet Cable
(9)A ND (10) I N P U T AND OUTPUT DEVICES
P R I N T E RS
(11)COMPUTERS I N A N E T WO R K
 •Interconnection of computer is called a
computer network.
 •Different ways of connecting computers in

network is called as network topology


NETWORK T Y P E S
1) Local Area Network (LA N)
2) Wide Area Network (WAN)

Technology advances have led to the birth of other


types of networks
3) Metropolitan Area Network (MAN)

4) Campus Area Network ( C A N )

5) Personal Area Network (PAN)

6) The Internet and internet


C O M P U T E R I N A N E T WO R K
The Internet is a vast network that connects computers
all over the world. Through the Internet, people can
share information and communicate from anywhere with
an Internet connection.
12)NETWORK H A R D WA R E
N E T WO R K H A R D WA R E

 •Network Interface C a rd
 • H u b and Switch

 •Bridge and Router


13) S O F T WA R E B A S I C S
 INSTRUCTIONS------PROGRAMS-------SOFTWARE------OPERATING
S YST E M .

 Software is a collection of instructions and data that tell the computer how to
work. This is in contrast to physical hardware, from which the system is built
and actually performs the work.

E X A M P L E : LAPTOP/PC/SIMPLE C O M P U T E R .
14) S O F T WA R E T Y P E S
 The 4 major types of computer software are:
1. Application Software
2. System Software
3. Programming Software
4. Driver Software
1)Application Software
M S Excel: It is spreadsheet software that you can use for presenting and
analyzing data.
Photoshop: It is a photo editing application software by Adobe. You can
use it to visually enhance, catalogue and share your pictures.
Skype: It is an online communication app that you can use for video chat,
voice calling and instant messaging.
Z O O M APP, T E A M S A PP, G O O G L E M E ET. . . E . T. C
2) System Software
 For desktop computers, laptops and tablets:
Microsoft Windows
Mac (for Apple devices)
Linux
For smartphones:
Apple’s iOS
Google’s Android
Windows Phone O S
3) Programming Software
 Eclipse – a Java language editor

 Coda – programming language editor for Mac

 Notepad++ – an open-source editor for windows

 Sublime Text – a cross-platform code editor for Mac,

Windows, and Linux


4) Driver Software
 Printer Driver
 Mouse Driver
 Network Card

5) Freeware(APPS)
 Google Chrome
 Google Meet
 Skype
 Instagram
 Snapchat
 teams/zoom apps
 Adobe reader
37
6)Shareware
 Adobe PhotoShop

 Adobe Illustrator

 Netflix App

 Matlab

 McAfee Antivirus

7)Open Source Software (for developing apps)


 Libre Office

 PHP

 G N U Image Manipulation Program (GIMP)

 LINUX/UNIX

38
8) Closed Source Software
 .NET

 J ava

 Android

 Microsoft Office

 Adobe PhotoShop

9) Utility Software
 Antivirus and security software

 File compressor

 Disk cleaner

 Disk defragmentation software

 Data backup software 39


BASIC CONCEPTS ( BEFORE UNDERSTANDING
C-PROGRAME).

 ALGORITHM
 F L O WC H A RT

 A LG O R I T H M : Step by step procedure


explanisation of a process.

 FLOWCHA RT: diagram which shows the process


of a system.
A L G O R I T H M TO A D D TWO N U M B E R S
https://courses.lumenlearning.com/ivytec

h-sdev-dev-1/chapter/flowchart-symbols-
8-3-
43
13/#:~:text=The%20two%20most%20co
%20a%20diamond.
m
mon%20types,usually%20denoted%20as
(2)OVERVIEW O F C

1.Basic structure of C-program.(6-Sections)


EX:1
EX:2
P RO G R A M I C E X A M P L E S
1./*Progame to display a text message*/----- DOCUMENTATION
SECTION

#include <stdio.h> //LINK S E C T I ON ( P R E - PRO C E S S O R


DIRECTIVES

void main() ------------------------------------- MAIN F U N C T I O N


SECTION

{
printf("Hello World!");
return 0;
}

Output
Hello, World!
2./*Progame to A D D two Numbers*/
#include<stdio.h > // stdio.h means standard input and output
void main() / /M A IN F U N C T IO N S E C T IO N
{
int a, b, sum;--------------------------------------DECLARATION PART
printf("Enter two no: ");
scanf("%d %d", &a, &b);
sum = a + b; -----------EXECUTABLE PART
printf("Sum : %d", sum);
return(0);
}

Output :
1
2
Enter two no: 5 6 48
Sum : 11
3./*Progame to Find A R E A and P E R I M E T E R of a
CIRCLE*/

 Algorithm
S T E P 1: Take radius as input from the user
S T E P 2: Calculate the area and Perimeter of circle
using,
area = (3.14)*r*r
Perimeter= = 2*3.14*radius
S T E P 3: Print the area and
perimeter of the Circle to
the screen
P RO G R A M

#include .h meand header file and dot(.) means we are including or


<stdio.h> // accessing header file
int main() OUTPUT
{
int radius; Enter the radius of a
float area, perimeter; circle: 10
printf("Enter the radius of a\n circle\n");
Area:
Perimeter:
scanf("%d", & radius);
area = 3.14*radius*radius;
perimeter = 2*3.14*radius;
printf("Perimeter of the
Circle = %f ", perimeter);
printf("Area of the Circle =
%f ", area);
return(0);
}
4./*Program to Find A R E A and P E R I M E T E R of a
RECTANGLE*/
#include <stdio.h>
#include
<math.h> Void
main()
{
float length, width,
area, perimeter;
printf("Enter the
length of the
rectangle");
scanf("%f",
&length);
printf("Enter the
width of the
rectangle");
scanf("%f", 51
&width);
area
OTHER BASIC PROGRAMES
A S S I G N M E N T -1 (3-questions)

5 /*C-Program to Find A R E A and P E R I M E T E R of


a TRIANGLE*/ ------QP Program
6 /*C-Program which takes as input P,T,R and
compute SI(Simple Interest) and display the
Result*/ ------QP Program
7 /*Write Algorithm, Flowchart and C-program to
find Biggest of Three numbers*/ ------QP
Program
Best online C-program compiler platform

https://www.programiz.com/c-
programming/online-compiler/
2.Execting a C-program:
1. Creating the program
2. Compiling the program
3. Linking the program with the functions that are needed from the C-
library
4. Executing the program.

1 .CREATING T H E P RO G R A M

S AV E and
QUIT
(Ctrl+S)
Mkdir Foldername Cd Foldername gedit Filename.c
(Ctrl+Q)
(2)&(3)COMPILI N G T H E P RO G R A M and L I N K I N G T H E P RO G R A M
WITH T H E F U N C T I O N S THAT A R E N E E D E D F RO M T H E C L I B R ARY
cc filename.c (ex: cc school.c)

4.Executing the program.


./a.out
Fig1.10(pg no:14): Process of compiling and running a C program.
TO K E N S ( B A S I C CONCEPTS)
 Tokens are the smallest elements of a program, which are meaningful
to the compiler.
(QP)The following are the types of tokens: Keywords, Identifiers,
Constant, Strings, Operators, etc.(7-types)
K E Y WO R D S

Keywords Serves as Basic building blocks of the programs and


it includes:-
variable(identifiers), datatypes.
3.Constant, Variable and Data-type.

Constant (Literals):
 A constant is a fixed value that cannot be changed after
defining. Ex :-pie value, a=10, sin45,tan 90,....etc
 They are also called literals.

WE are having many types in Constants and they are:


Integer
1) Enumeration Constants
2) Floating Point Constants
3) Character Constants
4) String Constants
5) Backslash Character Constants
•This program has the constant Radius and PI.
•They are defined at the beginning.
•Those values cannot be changed in the program.
•R A D I U S and P I are constants.
•The compiler uses the assigned values of those constants to calculate
the area.
The same example using const keyword is as follows.

•The R A D I U S and PI are constants.


•The compiler uses the assigned values to find the area of the circle.
•Moreover, an enum can be also used to define a constant.
Refer the below example.
enum week {sun, mon, tue, wed, thurs, fri, sat};
The week is variable, and sun, mon, tue, etc. are enumeration constants.
They have the values 0,1,2, 3 etc. respectively. 61
Backslash character constants:
VA R I A B L E (Identifiers)

 A variable is a container to hold data.


 It is a name to identify the storage area.
 Every variable has a unique name to identify it.

C is a case-sensitive language. Therefore, the variable name width is


different from W I DT H .

EX: 1)radius, perimeter and Area are variable in c-program to find area
and perimeter of a circle
2) length, width, area, perimeter are variable in c-program to find area
and perimeter of a Rectangle.
•The width and length are variables that can store integers.
• They are assigned the values 10 and 20.
• The values of these variables are used to calculate the area and
perimeter.
• Finally, the results are printed to the console.
DATAT Y P E S :

Variables in C are associated with data type. Each data type requires
an amount of memory and performs specific operations.
There are some common data types in C −
 int − Used to store an integer value.
 char − Used to store a single character.
 float − Used to store decimal numbers with single precision.

double − Used to store decimal numbers with double precision .

Here is the syntax of datatypes in C


language
data_type variable_name;
/*Program to show different data-types*/

#include <stdio.h>
int main()
{
// datatypes
int a = 10;
char b = 'S';
float c = 2.88;
double d =
28.888;
printf("Integer datatype : %d\n",a);
printf("Character datatype : %c\n",b);
printf("Float datatype : %f \n",c);
printf("Double Float datatype : %lf \
n",d);
return 0;
}
OUTPUT

 Integer datatype : 10
 Character datatype : S
 Float datatype : 2.880000
 Double Float datatype : 28.888000
4.Operators and Expression.
Operators:
D E F I N I T I O N : - An operator is a symbol that tells the compiler to perform a certain
mathematical or logical manipulation .

C operators can be classified into following types:


1) Arithmetic operators
2) Relational operators
3) Logical operators
4) Bitwise operators
5) Assignment operators
6) Conditional operators
7) Special operators
Arithmetic operators

5/5=1(
5%5=0
Relational operators
Logical operators
Bitwise operators

00001<<2 = 00101
0010>>1 = 0001
Assignment Operators
Assignment operators supported by C language are as follows.
Conditional operator
The conditional operators in C language are known by two more names

1) Ternary Operator
2) ? : Operator

It is actually the if condition that we use in C language decision making, but


using conditional operator, we turn the if condition statement into a short
and simple operator.

The syntax of a conditional operator is :

expression 1 ? expression 2: expression 3


Explanation:

 The question mark "?" in the syntax represents


the if part.
The first expression (expression 1) generally returns
either true or false, based on which it is decided
whether (expression 2) will be executed or (expression
3)
 If (expression 1) returns true then the

expression on the left side of " : " i.e (expression 2) is


executed.
 If (expression 1) returns false then the

expression on the right side of " : " i.e (expression 3)


is executed .
 Special operator
EXPRESSION:
Definition: An expression is a combination of operators,
constants and variables. An expression may consist of one or
more operands, and zero or more operators to produce a value.
EX: a+b=c , s-1/7*f ,...... . . etc

.
Constant expressions: Constant Expressions consists of only constant
values. A constant value is one that doesn’t change.
E x amples: 5, 10 + 5 / 6.0, 'x’

Integral expressions: Integral Expressions are those which produce


integer results after implementing all the automatic and explicit type
conversions.
Examples: x, x * y, x + int( 5.0).
where x and y are integer variables.

Floating expressions: Float Expressions are which produce floating


point results after implementing all the automatic and explicit type
conversions.
Examples: x + y, 10.75
where x and y are floating point variables.
Relational expressions: Relational Expressions yield results of
type bool which takes a value true or false. When arithmetic
expressions are used on either side of a relational operator, they
will be evaluated first and then the results compared. Relational
expressions are also known as Boolean expressions.
Examples: x <= y, x + y > 2

Logical expressions: Logical Expressions combine two or more


relational expressions and produces bool type results.
Examples: x > y & & x == 10, x == 10 | | y == 5

Pointer expressions: Pointer Expressions produce address


values.
Examples:&x, ptr, ptr++
where x is a variable and ptr is a pointer.
Bitwise expressions: Bitwise Expressions are used to
manipulate data at bit level. They are basically used for
testing or shifting bits.

E xa mples: x << 3 shifts three bit position to left


y >> 1 shifts one bit position to right.

Note: An expression may also use combinations of the above


expressions. Such expressions are known as compound
expressions.
P RO G R A M AT I C P RO B L E M S
O N O P E R ATO RS A N D E X P R E S S I O N

2-TYPES:-

1. Convert Mathematical Expression into C Expression.


2.Evaluate the Expression
1. Convert Mathematical
Expression into C Expression.
B A S IC S
TYPE-1 (2-marks)
AS S I G N M E N T - 2 (7- EXPRE SSION)
 TYPE-2 (10/8-marks)
(QP)
2.Evaluate the Expression
B A S I C R E F E R E N C E TA B L E F O R - P R E C E D E N C E and
A S S O C I AT I V I T Y
BASICS:
Pre-increment/decrement-ex: ++5 = 6 , - -5 = 4
Post-increment/decrement-ex: 5++ = 5 , 5- - =
5
W H E N U A R E H AV I N G (+, -, * , /, %) I N A S A M E E Q UAT I O N
Note: F I R S T Solve post increment/decrement in given 97
Equations
C O M P L E T E 8/10-MARKS P RO B L E M
N OT E : a+= b means a= a + b
(assignment operator)

92
93
94
95

You might also like