SlideShare a Scribd company logo
1 of 21
Input Operations,
Arrays, Declarations, Expressions,
Statements, Symbolic constant
PROGRAMMING IN C
Revision
•It is possible to utilize an uppercase keyword as an identifier.
•Find out whether following are valid identifier. If not why?
◦ 12,245
◦ 36.0
◦ 10 20 30
◦ 123-45-6789
◦ 0900
PROGRAMMING IN C
unsigned and long integer constants
PROGRAMMING IN C
Average of Three Numbers
step 1: Get the input of three real numbers and store in n1,n2, n3
step 2: Calculate Total <- n1 + n2 + n3
step 3: Calculate average <- Total / 3
step 4: Print Total and average
PROGRAMMING IN C
Simple Interest Calculation ??????????????
PROGRAMMING IN C
Simple Interest Calculation
#include<stdio.h>
int main( )
{
int p, n ;
float r, si ;
p = 1000 ;
n = 3 ;
r = 8.5 ;
si = p * n * r / 100 ;
printf ( "%f" , si ) ;
}
PROGRAMMING IN C
Input operations
• Input operations are used to read user input from the keyboard
• scanf() function is used to read multiple data values of different data types from the keyboard
Syntax:
scanf(“control string”, arg1, arg2, ………. argn);
 Control string (format string) specifies the field format
 Arguments arg1, arg2, …, argn specify the address of locations where
the data is stored
Inputting integer numbers:
%d
Percentage sign (%) indicates conversion specification, a data type character ( or type specifier)
Example:
scanf(“%d %d”, &number1, &number2);
PROGRAMMING IN C
Input operations(cont…)
Inputting real numbers: %f
Example:
scanf(“%f %f”, &number1, &number2);
This statement will read the data: 50.35 23.0345
Inputting character strings: %s or %c
Example:
scanf(“ %s ”, name);
This statement will read the data: SASTRA
PROGRAMMING IN C
Input operations(cont…)
PROGRAMMING IN C
Home Work
1)Area of Rectangle
2)Area of Triangle
3)Farenheit to celcius conversion
4)Celcius to Farenheit conversion
PROGRAMMING IN C
Array
An array is an identifier that refers to a collection of data items that all have the same name.
The data items must all be of the same type
The individual array elements are distinguished from one another by the value that is assigned
to a subscript.
Example
x is a 10-element array.
◦ The first element is referred to as x [ 0J ,the second as x [ 1J ,and so on.
◦ The last element will be x [9J .
If the array contains n elements, the subscript will be an integer quantity whose values range
from 0 to n-1 .
PROGRAMMING IN C
Array (Cont….)
n-character string will require an (n+l )-element array, because of the null character (O) that is
automatically placed at the end of the string.
PROGRAMMING IN C
Declarations
A declaration associates a group of variables with a specific data type.
All variables must be declared before they can appear in executable statements
It consists of a data type, followed by one or more variable names, ending with a semicolon
PROGRAMMING IN C
Declarations (Cont…)
Initial values can be assigned to variables within a type declaration
PROGRAMMING IN C
EXPRESSIONS
An expression represents a single data item, such as a number or a character.
It may consist of a single entity, such as a constant, a variable, an array element or a reference
to a function.
It may also consist of some combination of such entities, interconnected by one or more
operators.
It can also represent logical conditions that are either true or false
true and false are represented by the integer values 1 and 0, respectively.
 Examples are shown there
PROGRAMMING IN C
STATEMENTS
A statement causes the computer to carry out some action.
Three different classes
◦ expression statements
◦ compound statements and
◦ control statements
Expression Statement
o consists of an expression followed by a semicolon.
o Several expression statements are shown below.
o a = 3;
o c = a + b ;
o ++i;
o p r i n t f ("Area = %f area) ;
PROGRAMMING IN C
STATEMENTS(cont..)
Compound statement
◦ A compound statement consists of several individual statements enclosed within a pair of braces { }.
◦ a compound statement does not end with a semicolon
◦ A typical compound statement is shown below.
{
p i = 3.141593;
circumference = 2. * p i * radius;
area = p i * radius * radius;
}
Control Statement
Control statements are used to create special program features, such as logical tests, loops and branches.
PROGRAMMING IN C
STATEMENTS(cont..)
Example
while (count <= n) {
p r i n t f ( ' x = ' ) ;
scanf ( "Skf" , &x) ;
sum += x;
++count;
}
PROGRAMMING IN C
Symbolic Constants
A symbolic constant is a name that substitutes for a sequence of characters.
The characters may represent a numeric constant, a character constant or a string constant.
Thus, a symbolic constant allows a name to appear in place of those constant
When a program is compiled, each occurrence of a symbolic constant is replaced by its
corresponding character sequence.
It usually defined at the beginning of a program
typically written in uppercase letters
does not end with a semicolon
PROGRAMMING IN C
Symbolic Constants(contd…)
Examples
#define TAXRATE 0.23
#define P I 3.141593
#define TRUE 1
#define FALSE 0
#define FRIEND "Susan“
Scenario 1
area = PI * radius * radius; statement will become area = 3.141593 * radius * radius;
PROGRAMMING IN C
Symbolic Constants(contd…)
Scenario2
#define CONSTANT 6.023E23
……
….
p r i n t f ( "CONSTANT = %f “,CONSTANT) ;
......
...... p r i n t f statement would become p r i n t f ( "CONSTANT = %f 6.023E23) ; ,
during the compilation process.
Advantage
readily identified than the information that they represent
easier to change the value of a single symbolic constant than to change every
occurrence of some numerical constant that may appear in several places within the
program.
PROGRAMMING IN C

More Related Content

Similar to 3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx

Similar to 3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx (20)

presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
2. operator
2. operator2. operator
2. operator
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
1 Revision Tour
1 Revision Tour1 Revision Tour
1 Revision Tour
 
Basics of c
Basics of cBasics of c
Basics of c
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
C PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT II
C PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT IIC PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT II
C PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT II
 
Java căn bản - Chapter3
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3
 
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
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
Ch03
Ch03Ch03
Ch03
 

More from ganeshkarthy

Lecture-5-Linear Regression-Tutorials.PPTX
Lecture-5-Linear Regression-Tutorials.PPTXLecture-5-Linear Regression-Tutorials.PPTX
Lecture-5-Linear Regression-Tutorials.PPTXganeshkarthy
 
Lecture-5-Linear Regression-Tutorials.PPTX
Lecture-5-Linear Regression-Tutorials.PPTXLecture-5-Linear Regression-Tutorials.PPTX
Lecture-5-Linear Regression-Tutorials.PPTXganeshkarthy
 
Lecture-6-Linear Regression-Gradient Descent-Tutorials.PPTX
Lecture-6-Linear Regression-Gradient Descent-Tutorials.PPTXLecture-6-Linear Regression-Gradient Descent-Tutorials.PPTX
Lecture-6-Linear Regression-Gradient Descent-Tutorials.PPTXganeshkarthy
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptganeshkarthy
 
CLOUD_COMPUTING_UNIT_2.pdf
CLOUD_COMPUTING_UNIT_2.pdfCLOUD_COMPUTING_UNIT_2.pdf
CLOUD_COMPUTING_UNIT_2.pdfganeshkarthy
 
CLOUD_COMPUTING_UNIT_1.pdf
CLOUD_COMPUTING_UNIT_1.pdfCLOUD_COMPUTING_UNIT_1.pdf
CLOUD_COMPUTING_UNIT_1.pdfganeshkarthy
 
Asynchronous Frameworks.pptx
Asynchronous Frameworks.pptxAsynchronous Frameworks.pptx
Asynchronous Frameworks.pptxganeshkarthy
 
Green computing PPT Notes.ppt
Green computing PPT Notes.pptGreen computing PPT Notes.ppt
Green computing PPT Notes.pptganeshkarthy
 
OOPS(CS8392)_Unit-I_Notes.ppt
OOPS(CS8392)_Unit-I_Notes.pptOOPS(CS8392)_Unit-I_Notes.ppt
OOPS(CS8392)_Unit-I_Notes.pptganeshkarthy
 
Unit-II(STATIC UML DIAGRAMS).ppt
Unit-II(STATIC UML DIAGRAMS).pptUnit-II(STATIC UML DIAGRAMS).ppt
Unit-II(STATIC UML DIAGRAMS).pptganeshkarthy
 
UNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docx
UNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docxUNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docx
UNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docxganeshkarthy
 
Unit-1_Notes(OOAD).pdf
Unit-1_Notes(OOAD).pdfUnit-1_Notes(OOAD).pdf
Unit-1_Notes(OOAD).pdfganeshkarthy
 

More from ganeshkarthy (13)

Lecture-5-Linear Regression-Tutorials.PPTX
Lecture-5-Linear Regression-Tutorials.PPTXLecture-5-Linear Regression-Tutorials.PPTX
Lecture-5-Linear Regression-Tutorials.PPTX
 
Lecture-5-Linear Regression-Tutorials.PPTX
Lecture-5-Linear Regression-Tutorials.PPTXLecture-5-Linear Regression-Tutorials.PPTX
Lecture-5-Linear Regression-Tutorials.PPTX
 
Lecture-6-Linear Regression-Gradient Descent-Tutorials.PPTX
Lecture-6-Linear Regression-Gradient Descent-Tutorials.PPTXLecture-6-Linear Regression-Gradient Descent-Tutorials.PPTX
Lecture-6-Linear Regression-Gradient Descent-Tutorials.PPTX
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
 
CLOUD_COMPUTING_UNIT_2.pdf
CLOUD_COMPUTING_UNIT_2.pdfCLOUD_COMPUTING_UNIT_2.pdf
CLOUD_COMPUTING_UNIT_2.pdf
 
CLOUD_COMPUTING_UNIT_1.pdf
CLOUD_COMPUTING_UNIT_1.pdfCLOUD_COMPUTING_UNIT_1.pdf
CLOUD_COMPUTING_UNIT_1.pdf
 
S16_Notes_CC.pptx
S16_Notes_CC.pptxS16_Notes_CC.pptx
S16_Notes_CC.pptx
 
Asynchronous Frameworks.pptx
Asynchronous Frameworks.pptxAsynchronous Frameworks.pptx
Asynchronous Frameworks.pptx
 
Green computing PPT Notes.ppt
Green computing PPT Notes.pptGreen computing PPT Notes.ppt
Green computing PPT Notes.ppt
 
OOPS(CS8392)_Unit-I_Notes.ppt
OOPS(CS8392)_Unit-I_Notes.pptOOPS(CS8392)_Unit-I_Notes.ppt
OOPS(CS8392)_Unit-I_Notes.ppt
 
Unit-II(STATIC UML DIAGRAMS).ppt
Unit-II(STATIC UML DIAGRAMS).pptUnit-II(STATIC UML DIAGRAMS).ppt
Unit-II(STATIC UML DIAGRAMS).ppt
 
UNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docx
UNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docxUNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docx
UNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docx
 
Unit-1_Notes(OOAD).pdf
Unit-1_Notes(OOAD).pdfUnit-1_Notes(OOAD).pdf
Unit-1_Notes(OOAD).pdf
 

Recently uploaded

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
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
 
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
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 

Recently uploaded (20)

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
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...
 
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 )
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 

3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx

  • 1. Input Operations, Arrays, Declarations, Expressions, Statements, Symbolic constant PROGRAMMING IN C
  • 2. Revision •It is possible to utilize an uppercase keyword as an identifier. •Find out whether following are valid identifier. If not why? ◦ 12,245 ◦ 36.0 ◦ 10 20 30 ◦ 123-45-6789 ◦ 0900 PROGRAMMING IN C
  • 3. unsigned and long integer constants PROGRAMMING IN C
  • 4. Average of Three Numbers step 1: Get the input of three real numbers and store in n1,n2, n3 step 2: Calculate Total <- n1 + n2 + n3 step 3: Calculate average <- Total / 3 step 4: Print Total and average PROGRAMMING IN C
  • 5. Simple Interest Calculation ?????????????? PROGRAMMING IN C
  • 6. Simple Interest Calculation #include<stdio.h> int main( ) { int p, n ; float r, si ; p = 1000 ; n = 3 ; r = 8.5 ; si = p * n * r / 100 ; printf ( "%f" , si ) ; } PROGRAMMING IN C
  • 7. Input operations • Input operations are used to read user input from the keyboard • scanf() function is used to read multiple data values of different data types from the keyboard Syntax: scanf(“control string”, arg1, arg2, ………. argn);  Control string (format string) specifies the field format  Arguments arg1, arg2, …, argn specify the address of locations where the data is stored Inputting integer numbers: %d Percentage sign (%) indicates conversion specification, a data type character ( or type specifier) Example: scanf(“%d %d”, &number1, &number2); PROGRAMMING IN C
  • 8. Input operations(cont…) Inputting real numbers: %f Example: scanf(“%f %f”, &number1, &number2); This statement will read the data: 50.35 23.0345 Inputting character strings: %s or %c Example: scanf(“ %s ”, name); This statement will read the data: SASTRA PROGRAMMING IN C
  • 10. Home Work 1)Area of Rectangle 2)Area of Triangle 3)Farenheit to celcius conversion 4)Celcius to Farenheit conversion PROGRAMMING IN C
  • 11. Array An array is an identifier that refers to a collection of data items that all have the same name. The data items must all be of the same type The individual array elements are distinguished from one another by the value that is assigned to a subscript. Example x is a 10-element array. ◦ The first element is referred to as x [ 0J ,the second as x [ 1J ,and so on. ◦ The last element will be x [9J . If the array contains n elements, the subscript will be an integer quantity whose values range from 0 to n-1 . PROGRAMMING IN C
  • 12. Array (Cont….) n-character string will require an (n+l )-element array, because of the null character (O) that is automatically placed at the end of the string. PROGRAMMING IN C
  • 13. Declarations A declaration associates a group of variables with a specific data type. All variables must be declared before they can appear in executable statements It consists of a data type, followed by one or more variable names, ending with a semicolon PROGRAMMING IN C
  • 14. Declarations (Cont…) Initial values can be assigned to variables within a type declaration PROGRAMMING IN C
  • 15. EXPRESSIONS An expression represents a single data item, such as a number or a character. It may consist of a single entity, such as a constant, a variable, an array element or a reference to a function. It may also consist of some combination of such entities, interconnected by one or more operators. It can also represent logical conditions that are either true or false true and false are represented by the integer values 1 and 0, respectively.  Examples are shown there PROGRAMMING IN C
  • 16. STATEMENTS A statement causes the computer to carry out some action. Three different classes ◦ expression statements ◦ compound statements and ◦ control statements Expression Statement o consists of an expression followed by a semicolon. o Several expression statements are shown below. o a = 3; o c = a + b ; o ++i; o p r i n t f ("Area = %f area) ; PROGRAMMING IN C
  • 17. STATEMENTS(cont..) Compound statement ◦ A compound statement consists of several individual statements enclosed within a pair of braces { }. ◦ a compound statement does not end with a semicolon ◦ A typical compound statement is shown below. { p i = 3.141593; circumference = 2. * p i * radius; area = p i * radius * radius; } Control Statement Control statements are used to create special program features, such as logical tests, loops and branches. PROGRAMMING IN C
  • 18. STATEMENTS(cont..) Example while (count <= n) { p r i n t f ( ' x = ' ) ; scanf ( "Skf" , &x) ; sum += x; ++count; } PROGRAMMING IN C
  • 19. Symbolic Constants A symbolic constant is a name that substitutes for a sequence of characters. The characters may represent a numeric constant, a character constant or a string constant. Thus, a symbolic constant allows a name to appear in place of those constant When a program is compiled, each occurrence of a symbolic constant is replaced by its corresponding character sequence. It usually defined at the beginning of a program typically written in uppercase letters does not end with a semicolon PROGRAMMING IN C
  • 20. Symbolic Constants(contd…) Examples #define TAXRATE 0.23 #define P I 3.141593 #define TRUE 1 #define FALSE 0 #define FRIEND "Susan“ Scenario 1 area = PI * radius * radius; statement will become area = 3.141593 * radius * radius; PROGRAMMING IN C
  • 21. Symbolic Constants(contd…) Scenario2 #define CONSTANT 6.023E23 …… …. p r i n t f ( "CONSTANT = %f “,CONSTANT) ; ...... ...... p r i n t f statement would become p r i n t f ( "CONSTANT = %f 6.023E23) ; , during the compilation process. Advantage readily identified than the information that they represent easier to change the value of a single symbolic constant than to change every occurrence of some numerical constant that may appear in several places within the program. PROGRAMMING IN C