SlideShare a Scribd company logo
1 of 41
Download to read offline
C_Programming
Part 3
ENG. KEROLES SHENOUDA
1
C Fundamentals
2
IdentifiersKeywords
Data Types
Operators
Comments
Statements
Constants
1.Integer constants
2.Floating-point
constants
3.Character constants
4.String constants
 Control Statements
 if
 switch
 goto
 for loop
 while loop
 do-while loop
 break
 continue
 Nested Loop
 null statement
 expression statement
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Conditional operators
Comma operators
Bitwise Operators
min = (x < y) ? x : y;
Identifier = (test expression)? Expression1: Expression2 ;
int i , j;
i=(j=10,j+20);
A set of expression separated by comma is a valid
constant in the C language
User Defined
enum typedef
Derived
Arrays
structure union
pointer
Primitive/Basic Types
Integer ValuesReal Values
signe
d
unsigned
Identifiers
 Identifiers are the names that are given to various program elements
such as variables, symbolic constants and functions.
 Identifier can be freely named, the following restrictions.
 Alphanumeric characters ( a ~ z , A~Z , 0~9 ) and half underscore ( _ )
can only be used.
 The first character of the first contain letters ( a ~ z , A~Z ) or half
underscore ( _ ) can only be used.
3
Identifiers
 Here are the rules you need to know:
 1. Identifier name must be a sequence of letter and digits, and must begin with a letter.
 2. The underscore character (‘_’) is considered as letter.
 3. Names shouldn't be a keyword (such as int , float, if ,break, for etc)
 4. Both upper-case letter and lower-case letter characters are allowed. However, they're not interchangeable.
 5. No identifier may be keyword.
 6. No special characters, such as semicolon,period,blank space, slash or comma are permitted
 Examples of legal and illegal identifiers follow, first some legal identifiers:
 float _number;
 float a;
 The following are illegal (it's your job to recognize why):
 float :e; float for; float 9PI; float .3.14; float 7g;
4
Keywords
 Keywords are standard identifiers that have standard predefined meaning in C. Keywords
are all lowercase, since uppercase and lowercase characters are not equivalent it's possible
to utilize an uppercase keyword as an identifier but it's not a good programming practice.
 1. Keywords can be used only for their intended purpose.
 2. Keywords can't be used as programmer defined identifier.
 3. The keywords can't be used as names for variables.
 The standard keywords are given below:
5
Controlling Program Flow 6
Conditions 7
Example : Using Conditions
#include "stdio.h"
#include "math.h"
void main()
{
int a = 9;
int b = 8;
int c = 12;
printf("%drn", a>b);
printf("%drn", b>c);
printf("%drn", a<=9);
printf("%drn", a!=9);
printf("%drn", (a-b)>(c-b));
printf("%drn", a>b && c>b);
printf("%drn", a>b && c<b);
printf("%drn", a>b || c<b);
printf("%drn", !(a<b));
printf("%drn", 3 && 0);
printf("%drn", -15 || 0);
printf("%drn", !(-15));
}
8
Example :Using Conditions
#include "stdio.h"
#include "math.h"
void main()
{
int a = 9;
int b = 8;
int c = 12;
printf("%drn", a>b); //prints 1
printf("%drn", b>c); //prints 0
printf("%drn", a<=9); //prints 1
printf("%drn", a!=9); //prints 0
printf("%drn", (a-b)>(c-b)); //prints 0
printf("%drn", a>b && c>b); //prints 1
printf("%drn", a>b && c<b); //prints 0
printf("%drn", a>b || c<b); //prints 1
printf("%drn", !(a<b)); //prints 1
printf("%drn", 3 && 0); //prints 0
printf("%drn", -15 || 0); //prints 1
printf("%drn", !(-15)); //prints 0
}
9
if Statement
if(/*if condition*/)
{
//if body
}
else if(/*else if condition*/)
{
//else if body
}
else if(/*else if condition*/)
{
//else if body
}
else
{
//else body
}
10
Calculate Circle Area or Circumference
11
In this program the user has to choose between calculating circle area or circle
circumference. The choice comes by taking a character from the keyboard using the (getche)
function. If the user presses „a‟ character it proceeds with area calculation and printing. If the
user presses „c‟ character it proceeds with circumference calculation and printing. If the user
presses other letters the program prints an error message.
12
Comparing Three Numbers
13
This program finds the largest value of the three given values.
14
Inline condition / Conditional operators
 Sometimes it is required to take a fast decision inside your statements; this is
called the inline
condition. Following examples illustrate the idea.
15
min = (x < y) ? x : y;
Identifier = (test expression)? Expression1: Expression2 ;
Calculate the Minimum
of Two Numbers
16
17
switch Statement
switch(/*switch expression*/)
{
case /*case value*/:
{
//case body
}
break;
...
...
...
case /* case value*/:
{
//case body
}
break;
default:
{
}
break;
}
18
Calculate
Circle Area or
Circumference
19
for Statement 20
Printing Hello World in a Loop 21
Printing Hello World in a Loop 22
Calculate the Summation of
values between 1 and 99
23
Calculate the Summation of
values between 1 and 99
24
Calculate the Average
Students Degrees
25
calculates the average students degree for any given students
number.
26
while Statement 27
Calculate the Summation of odd values
between 1 and 99
28
Calculate the Average Students Degrees 29
Important:
break
statement is
used to exit
from any loop
type.
do…while Statement 30
Calculate Polynomial Value 31
goto Statement 32
goto Statement 33
break statement
 The break statement is a jump
instruction and can be used inside a
switch construct, for loop,
while loop and do-while loop.
 The execution of break statement
causes immediate exit from the
concern construct and the control is
transferred to the statement
following the loop.
34
break statement
 The break statement is a jump instruction
and can be used inside a switch construct,
for loop, while loop and do-while
loop.
 The execution of break statement causes
immediate exit from the concern construct
and the control is transferred to the
statement following the loop.
35
continue statement
 Continue statement is used to
continue the next iteration of for loop,
while loop and do-while loops. So, the
remaining statements are skipped
within the loop for that particular
iteration.
 Syntax : continue;
36
continue statement
 Continue statement is used to
continue the next iteration of for loop,
while loop and do-while loops. So, the
remaining statements are skipped
within the loop for that particular
iteration.
 Syntax : continue;
37
Nested loop
 In many cases we may use loop statement inside another looping statement.
This type of looping is called nested loop
38
Write a program that produces
the following output:
39
Follow Chapter 3:
Controlling Program
Flow
C PROGRAMMING FOR ENGINEERS, DR. MOHAMED SOBH
40
References 41
 The Case for Learning C as Your First Programming Language
 A Tutorial on Data Representation
 std::printf, std::fprintf, std::sprintf, std::snprintf…..
 C Programming for Engineers, Dr. Mohamed Sobh
 C programming expert.
 fresh2refresh.com/c-programming

More Related Content

What's hot

C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo dattaApurbo Datta
 
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 LanguageVincenzo De Florio
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoMark John Lado, MIT
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1Rumman Ansari
 
Embedded c programming
Embedded c programmingEmbedded c programming
Embedded c programmingPriyaDYP
 
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 - JavaTpointJavaTpoint.Com
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questionsadarshynl
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++oggyrao
 

What's hot (17)

C programming part2
C programming part2C programming part2
C programming part2
 
Embedded c
Embedded cEmbedded c
Embedded c
 
Session 5-exersice
Session 5-exersiceSession 5-exersice
Session 5-exersice
 
C programming session5
C programming  session5C programming  session5
C programming session5
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo datta
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming part4
C programming part4C programming part4
C programming part4
 
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
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
First session quiz
First session quizFirst session quiz
First session quiz
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1
 
Embedded c programming
Embedded c programmingEmbedded c programming
Embedded c programming
 
Coding verilog
Coding verilogCoding verilog
Coding verilog
 
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
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questions
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 

Viewers also liked (15)

Homework 2
Homework 2Homework 2
Homework 2
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
K vector embedded_linux_workshop
K vector embedded_linux_workshopK vector embedded_linux_workshop
K vector embedded_linux_workshop
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Automative basics v3
Automative basics v3Automative basics v3
Automative basics v3
 
Microcontroller part 5
Microcontroller part 5Microcontroller part 5
Microcontroller part 5
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part4
C programming part4C programming part4
C programming part4
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Microcontroller part 9_v1
Microcontroller part 9_v1Microcontroller part 9_v1
Microcontroller part 9_v1
 

Similar to C programming session3

C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYRajeshkumar Reddy
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxKrishanPalSingh39
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 SlidesRakesh Roshan
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing TutorialMahira Banu
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpen Gurukul
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentationnadim akber
 

Similar to C programming session3 (20)

C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Unit 1
Unit 1Unit 1
Unit 1
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
Programming in C
Programming in CProgramming in C
Programming in C
 
What is c
What is cWhat is c
What is c
 
C programming
C programmingC programming
C programming
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Programming-in-C
Programming-in-CProgramming-in-C
Programming-in-C
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentation
 
C fundamental
C fundamentalC fundamental
C fundamental
 

More from Keroles karam khalil (20)

C basics quiz part 1_solution
C basics quiz part 1_solutionC basics quiz part 1_solution
C basics quiz part 1_solution
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
 
Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Automotive embedded systems part6 v1
Automotive embedded systems part6 v1
 
Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1
 
Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Automotive embedded systems part4 v1
Automotive embedded systems part4 v1
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1
 
Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Automotive embedded systems part8 v1
Automotive embedded systems part8 v1
 
Quiz 10
Quiz 10Quiz 10
Quiz 10
 
Homework 6
Homework 6Homework 6
Homework 6
 
Homework 5 solution
Homework 5 solutionHomework 5 solution
Homework 5 solution
 
Notes part7
Notes part7Notes part7
Notes part7
 
Homework 5
Homework 5Homework 5
Homework 5
 
Notes part6
Notes part6Notes part6
Notes part6
 
Homework 4 solution
Homework 4 solutionHomework 4 solution
Homework 4 solution
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 

Recently uploaded (20)

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 

C programming session3

  • 2. C Fundamentals 2 IdentifiersKeywords Data Types Operators Comments Statements Constants 1.Integer constants 2.Floating-point constants 3.Character constants 4.String constants  Control Statements  if  switch  goto  for loop  while loop  do-while loop  break  continue  Nested Loop  null statement  expression statement Arithmetic operators Relational operators Logical operators Assignment operators Conditional operators Comma operators Bitwise Operators min = (x < y) ? x : y; Identifier = (test expression)? Expression1: Expression2 ; int i , j; i=(j=10,j+20); A set of expression separated by comma is a valid constant in the C language User Defined enum typedef Derived Arrays structure union pointer Primitive/Basic Types Integer ValuesReal Values signe d unsigned
  • 3. Identifiers  Identifiers are the names that are given to various program elements such as variables, symbolic constants and functions.  Identifier can be freely named, the following restrictions.  Alphanumeric characters ( a ~ z , A~Z , 0~9 ) and half underscore ( _ ) can only be used.  The first character of the first contain letters ( a ~ z , A~Z ) or half underscore ( _ ) can only be used. 3
  • 4. Identifiers  Here are the rules you need to know:  1. Identifier name must be a sequence of letter and digits, and must begin with a letter.  2. The underscore character (‘_’) is considered as letter.  3. Names shouldn't be a keyword (such as int , float, if ,break, for etc)  4. Both upper-case letter and lower-case letter characters are allowed. However, they're not interchangeable.  5. No identifier may be keyword.  6. No special characters, such as semicolon,period,blank space, slash or comma are permitted  Examples of legal and illegal identifiers follow, first some legal identifiers:  float _number;  float a;  The following are illegal (it's your job to recognize why):  float :e; float for; float 9PI; float .3.14; float 7g; 4
  • 5. Keywords  Keywords are standard identifiers that have standard predefined meaning in C. Keywords are all lowercase, since uppercase and lowercase characters are not equivalent it's possible to utilize an uppercase keyword as an identifier but it's not a good programming practice.  1. Keywords can be used only for their intended purpose.  2. Keywords can't be used as programmer defined identifier.  3. The keywords can't be used as names for variables.  The standard keywords are given below: 5
  • 8. Example : Using Conditions #include "stdio.h" #include "math.h" void main() { int a = 9; int b = 8; int c = 12; printf("%drn", a>b); printf("%drn", b>c); printf("%drn", a<=9); printf("%drn", a!=9); printf("%drn", (a-b)>(c-b)); printf("%drn", a>b && c>b); printf("%drn", a>b && c<b); printf("%drn", a>b || c<b); printf("%drn", !(a<b)); printf("%drn", 3 && 0); printf("%drn", -15 || 0); printf("%drn", !(-15)); } 8
  • 9. Example :Using Conditions #include "stdio.h" #include "math.h" void main() { int a = 9; int b = 8; int c = 12; printf("%drn", a>b); //prints 1 printf("%drn", b>c); //prints 0 printf("%drn", a<=9); //prints 1 printf("%drn", a!=9); //prints 0 printf("%drn", (a-b)>(c-b)); //prints 0 printf("%drn", a>b && c>b); //prints 1 printf("%drn", a>b && c<b); //prints 0 printf("%drn", a>b || c<b); //prints 1 printf("%drn", !(a<b)); //prints 1 printf("%drn", 3 && 0); //prints 0 printf("%drn", -15 || 0); //prints 1 printf("%drn", !(-15)); //prints 0 } 9
  • 10. if Statement if(/*if condition*/) { //if body } else if(/*else if condition*/) { //else if body } else if(/*else if condition*/) { //else if body } else { //else body } 10
  • 11. Calculate Circle Area or Circumference 11 In this program the user has to choose between calculating circle area or circle circumference. The choice comes by taking a character from the keyboard using the (getche) function. If the user presses „a‟ character it proceeds with area calculation and printing. If the user presses „c‟ character it proceeds with circumference calculation and printing. If the user presses other letters the program prints an error message.
  • 12. 12
  • 13. Comparing Three Numbers 13 This program finds the largest value of the three given values.
  • 14. 14
  • 15. Inline condition / Conditional operators  Sometimes it is required to take a fast decision inside your statements; this is called the inline condition. Following examples illustrate the idea. 15 min = (x < y) ? x : y; Identifier = (test expression)? Expression1: Expression2 ;
  • 16. Calculate the Minimum of Two Numbers 16
  • 17. 17
  • 18. switch Statement switch(/*switch expression*/) { case /*case value*/: { //case body } break; ... ... ... case /* case value*/: { //case body } break; default: { } break; } 18
  • 21. Printing Hello World in a Loop 21
  • 22. Printing Hello World in a Loop 22
  • 23. Calculate the Summation of values between 1 and 99 23
  • 24. Calculate the Summation of values between 1 and 99 24
  • 25. Calculate the Average Students Degrees 25 calculates the average students degree for any given students number.
  • 26. 26
  • 28. Calculate the Summation of odd values between 1 and 99 28
  • 29. Calculate the Average Students Degrees 29 Important: break statement is used to exit from any loop type.
  • 34. break statement  The break statement is a jump instruction and can be used inside a switch construct, for loop, while loop and do-while loop.  The execution of break statement causes immediate exit from the concern construct and the control is transferred to the statement following the loop. 34
  • 35. break statement  The break statement is a jump instruction and can be used inside a switch construct, for loop, while loop and do-while loop.  The execution of break statement causes immediate exit from the concern construct and the control is transferred to the statement following the loop. 35
  • 36. continue statement  Continue statement is used to continue the next iteration of for loop, while loop and do-while loops. So, the remaining statements are skipped within the loop for that particular iteration.  Syntax : continue; 36
  • 37. continue statement  Continue statement is used to continue the next iteration of for loop, while loop and do-while loops. So, the remaining statements are skipped within the loop for that particular iteration.  Syntax : continue; 37
  • 38. Nested loop  In many cases we may use loop statement inside another looping statement. This type of looping is called nested loop 38
  • 39. Write a program that produces the following output: 39
  • 40. Follow Chapter 3: Controlling Program Flow C PROGRAMMING FOR ENGINEERS, DR. MOHAMED SOBH 40
  • 41. References 41  The Case for Learning C as Your First Programming Language  A Tutorial on Data Representation  std::printf, std::fprintf, std::sprintf, std::snprintf…..  C Programming for Engineers, Dr. Mohamed Sobh  C programming expert.  fresh2refresh.com/c-programming