SlideShare a Scribd company logo
1 of 21
Download to read offline
ZMZ JANUARY 2012




         PROGRAMMING 1
                   BEB14103

Lecture 1
        1
DATA TYPES
         Topic Outcomes
• The students are able to identify four
  standard types of data in C
• The students are able to declare the
  variables according to the data types
• The students are able to create C
  programs with various of data types

 2
INTRODUCTION
                         Data
                        types

    int         float           char   void

There are four basic data types :
    •   Int
    •   Float
    •   Char
    •   Void

3
INTEGER


• Integer is number without the fraction part
• Support three different sizes (1 byte, 2
  bytes and 4 bytes)
• An integer constant must have at least
  one digit
4
CONT..
• It must not have a decimal point
• It can be either positive or negative
• If no sign precedes an integer
  constant it is assumed to be positive
• No commas or blanks are allowed
  within an integer constant
• Examples :

    426   +782   -8000   -7605
5
CHAR
• The letters of the alphabet
• Most computers use the American Standard
  Code for Information Interchange (ASCII)
• The maximum length of a character constant
  can be 1 character
• Examples :
  • 'A'
  • 'I'
  • '5'
  • '='

    6
FLOAT


•       Number with a fractional part, such as 43.32
•       Support three different sizes of floating point data types: float,
        double and long double
•       Double provides twice the precision of float
•       Floats typically take up 4 bytes
•       Doubles takes up 8 bytes
•       Long double takes 10 bytes
    7
VOID
•       The void type has no values therefore we cannot
        declare it as variable as we did in case of integer
        and float.
•       The void data type is usually used with function
        to specify its type.
•       Like in in the first C program we declared
        “main()” as void type because it does not return
        any value.

    8
RANGE OF DATA TYPES IN C




9
VARIABLES
•        Variables are named memory
         locations that have a type.
•        Must be declared and defined
•        Declaration is used to name an
         object such as a variable
•        Definitions are used to create the
         object
•        A variable cannot be type void
    10
VARIABLE DECLARATION




11
CONT..
In order to use a variable in our program we must first
declare it

HOW? A declaration statement has the following format:

type variable name;
–type : what kind of data will be stored in that location
  (integer?character? floating point?)
–variable name: what is the name of the variable?
–semi-colon : indicates this is a statement!

int num_students; // declaration
num_students= 22; // initialization
 12
EXAMPLE 2.1
#include <stdio.h>
main()
{
  int num1, num2, sum;
  printf(“Enter one decimal number:”);
  scanf(“%d”, &num1);
  printf(“Enter another decimal number:”);
  scanf(“%d”, &num2);
  sum = num1 + num2;
  printf(“nSum of %d and %d is %d ”, num1, num2, sum);
  return 0;
}
 13
EXAMPLE 2.2
#include <stdio.h>
main()
{
  float area_rectangle, width, length;
  printf(“Enter the length:”);
  scanf(“%f”, &length);
  printf(“Enter the width:”);
  scanf(“%f”, &width);
  area_rectangle = length * width;
  printf(“nArea of the rectangular is %f ”, area_rectangle);
  return 0;
}
 14
EXAMPLE 2.3
#include <stdio.h>
main()
{
     double pi, height, radius, base, volume;
     pi = 3.142;
     printf(“Enter the height the cone:”);
     scanf(“%lf”, &height);
     printf(“Enter the radius of the cone:”);
     scanf(“%lf”, &radius);
     base = pi * radius * radius;
     volume = (1.0/3.0) * base * height;
     printf(“nThe volume of a cone is %f ”, volume);
     return 0;
}

    15
#define
/*You may also associate constant using #define preprocessor directive*/
#include <stdio.h>
#define pi 3.142
main()
{
     double height, radius, base, volume;
     printf(“Enter the height the cone:”);
     scanf(“%lf”, &height);
     printf(“Enter the radius of the cone:”);
     scanf(“%lf”, &radius);
     base = pi * radius * radius;
     volume = (1.0/3.0) * base * height;
     printf(“nThe volume of a cone is %f ”, volume);
     return 0;
}
    16
EXAMPLE 2.4
#include <stdio.h>

main()
{
char Letter;
Letter = 'x';
printf(“nThe letter is %c ”, Letter);
return 0;
}

 17
STANDARD OUTPUT
•   printf Function
    •   prints information to the screen
    •   requires two arguments
        • control string
        • conversion specifier

Example
• double angle = 45.5;
• printf(“Angle = %.2f degrees n”, angle);

Output:
• Angle = 45.50 degrees
STANDARD INPUT
•   scanf Function
    • inputs values from the keyboard
    • required arguments
       • control string
       • memory locations that correspond to
         the specifiers in the control string

Example:

•   double distance;
•   scanf("%lf", &distance);
SUMMARY
•    There are four standard data types can be use in
     C program which are:
     • Integer
     • Float
     • Char
     • Void
•    Everytime you want to use a variable, the
     declaration must be made
•    To associate the variables with the data types,
     you can use standard input and output function

    20
REFERENCE
Hanly, J. R. & Koffman, E. B (2001). C
Program Design for Engineers. Addison
Wesley Longman.

Deitel, P & Deitel H (2008). C How to
Program. Pearson Education Inc.




21

More Related Content

What's hot (18)

Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
 
Basics of C porgramming
Basics of C porgrammingBasics of C porgramming
Basics of C porgramming
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 
Introduction to C
Introduction to CIntroduction to C
Introduction to C
 
What is c
What is cWhat is c
What is c
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
 
Constant and variacles in c
Constant   and variacles in cConstant   and variacles in c
Constant and variacles in c
 
Moving Average Filter in C
Moving Average Filter in CMoving Average Filter in C
Moving Average Filter in C
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
SPL 5 | scanf in C
SPL 5 | scanf in CSPL 5 | scanf in C
SPL 5 | scanf in C
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
C language basics
C language basicsC language basics
C language basics
 
C tokens
C tokensC tokens
C tokens
 

Viewers also liked

构建私有云计算平台的Eucalyptus架构分析
构建私有云计算平台的Eucalyptus架构分析构建私有云计算平台的Eucalyptus架构分析
构建私有云计算平台的Eucalyptus架构分析liangxiao0315
 
Pharmalinks Global Regulatory Partners
Pharmalinks Global Regulatory PartnersPharmalinks Global Regulatory Partners
Pharmalinks Global Regulatory Partnerstemreez
 
基于云计算平台的移动Iptv系统设计及负载均衡技术研究
基于云计算平台的移动Iptv系统设计及负载均衡技术研究基于云计算平台的移动Iptv系统设计及负载均衡技术研究
基于云计算平台的移动Iptv系统设计及负载均衡技术研究liangxiao0315
 
腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍George Ang
 
Hadoop开发者入门专刊
Hadoop开发者入门专刊Hadoop开发者入门专刊
Hadoop开发者入门专刊liangxiao0315
 
基于Eucalyptus的教育知识服务体系模型研究(1)
基于Eucalyptus的教育知识服务体系模型研究(1)基于Eucalyptus的教育知识服务体系模型研究(1)
基于Eucalyptus的教育知识服务体系模型研究(1)liangxiao0315
 

Viewers also liked (9)

构建私有云计算平台的Eucalyptus架构分析
构建私有云计算平台的Eucalyptus架构分析构建私有云计算平台的Eucalyptus架构分析
构建私有云计算平台的Eucalyptus架构分析
 
Pharmalinks Global Regulatory Partners
Pharmalinks Global Regulatory PartnersPharmalinks Global Regulatory Partners
Pharmalinks Global Regulatory Partners
 
Function creation and function call in c copy
Function creation and function call in c   copyFunction creation and function call in c   copy
Function creation and function call in c copy
 
基于云计算平台的移动Iptv系统设计及负载均衡技术研究
基于云计算平台的移动Iptv系统设计及负载均衡技术研究基于云计算平台的移动Iptv系统设计及负载均衡技术研究
基于云计算平台的移动Iptv系统设计及负载均衡技术研究
 
腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍腾讯大讲堂25 企业级搜索托管平台介绍
腾讯大讲堂25 企业级搜索托管平台介绍
 
2
22
2
 
Hadoop开发者入门专刊
Hadoop开发者入门专刊Hadoop开发者入门专刊
Hadoop开发者入门专刊
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
基于Eucalyptus的教育知识服务体系模型研究(1)
基于Eucalyptus的教育知识服务体系模型研究(1)基于Eucalyptus的教育知识服务体系模型研究(1)
基于Eucalyptus的教育知识服务体系模型研究(1)
 

Similar to Zaridah lecture2

C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginnersophoeutsen2
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingEric Chou
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxLESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxjoachimbenedicttulau
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
C-PROGRAMMING.pdf
C-PROGRAMMING.pdfC-PROGRAMMING.pdf
C-PROGRAMMING.pdfTushalJain3
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptxMangala R
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageDr.Florence Dayana
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in Cbabuk110
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1Ali Raza Jilani
 

Similar to Zaridah lecture2 (20)

C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
C language
C languageC language
C language
 
C
CC
C
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
LESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptxLESSON1-C_programming (1).GRADE 8 LESSONpptx
LESSON1-C_programming (1).GRADE 8 LESSONpptx
 
C programming language
C programming languageC programming language
C programming language
 
C language
C languageC language
C language
 
Lec-1c.pdf
Lec-1c.pdfLec-1c.pdf
Lec-1c.pdf
 
C language
C languageC language
C language
 
C-PROGRAMMING.pdf
C-PROGRAMMING.pdfC-PROGRAMMING.pdf
C-PROGRAMMING.pdf
 
Cpu
CpuCpu
Cpu
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
C language updated
C language updatedC language updated
C language updated
 
c-introduction.pptx
c-introduction.pptxc-introduction.pptx
c-introduction.pptx
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in C
 
C language
C languageC language
C language
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Zaridah lecture2

  • 1. ZMZ JANUARY 2012 PROGRAMMING 1 BEB14103 Lecture 1 1
  • 2. DATA TYPES Topic Outcomes • The students are able to identify four standard types of data in C • The students are able to declare the variables according to the data types • The students are able to create C programs with various of data types 2
  • 3. INTRODUCTION Data types int float char void There are four basic data types : • Int • Float • Char • Void 3
  • 4. INTEGER • Integer is number without the fraction part • Support three different sizes (1 byte, 2 bytes and 4 bytes) • An integer constant must have at least one digit 4
  • 5. CONT.. • It must not have a decimal point • It can be either positive or negative • If no sign precedes an integer constant it is assumed to be positive • No commas or blanks are allowed within an integer constant • Examples : 426 +782 -8000 -7605 5
  • 6. CHAR • The letters of the alphabet • Most computers use the American Standard Code for Information Interchange (ASCII) • The maximum length of a character constant can be 1 character • Examples : • 'A' • 'I' • '5' • '=' 6
  • 7. FLOAT • Number with a fractional part, such as 43.32 • Support three different sizes of floating point data types: float, double and long double • Double provides twice the precision of float • Floats typically take up 4 bytes • Doubles takes up 8 bytes • Long double takes 10 bytes 7
  • 8. VOID • The void type has no values therefore we cannot declare it as variable as we did in case of integer and float. • The void data type is usually used with function to specify its type. • Like in in the first C program we declared “main()” as void type because it does not return any value. 8
  • 9. RANGE OF DATA TYPES IN C 9
  • 10. VARIABLES • Variables are named memory locations that have a type. • Must be declared and defined • Declaration is used to name an object such as a variable • Definitions are used to create the object • A variable cannot be type void 10
  • 12. CONT.. In order to use a variable in our program we must first declare it HOW? A declaration statement has the following format: type variable name; –type : what kind of data will be stored in that location (integer?character? floating point?) –variable name: what is the name of the variable? –semi-colon : indicates this is a statement! int num_students; // declaration num_students= 22; // initialization 12
  • 13. EXAMPLE 2.1 #include <stdio.h> main() { int num1, num2, sum; printf(“Enter one decimal number:”); scanf(“%d”, &num1); printf(“Enter another decimal number:”); scanf(“%d”, &num2); sum = num1 + num2; printf(“nSum of %d and %d is %d ”, num1, num2, sum); return 0; } 13
  • 14. EXAMPLE 2.2 #include <stdio.h> main() { float area_rectangle, width, length; printf(“Enter the length:”); scanf(“%f”, &length); printf(“Enter the width:”); scanf(“%f”, &width); area_rectangle = length * width; printf(“nArea of the rectangular is %f ”, area_rectangle); return 0; } 14
  • 15. EXAMPLE 2.3 #include <stdio.h> main() { double pi, height, radius, base, volume; pi = 3.142; printf(“Enter the height the cone:”); scanf(“%lf”, &height); printf(“Enter the radius of the cone:”); scanf(“%lf”, &radius); base = pi * radius * radius; volume = (1.0/3.0) * base * height; printf(“nThe volume of a cone is %f ”, volume); return 0; } 15
  • 16. #define /*You may also associate constant using #define preprocessor directive*/ #include <stdio.h> #define pi 3.142 main() { double height, radius, base, volume; printf(“Enter the height the cone:”); scanf(“%lf”, &height); printf(“Enter the radius of the cone:”); scanf(“%lf”, &radius); base = pi * radius * radius; volume = (1.0/3.0) * base * height; printf(“nThe volume of a cone is %f ”, volume); return 0; } 16
  • 17. EXAMPLE 2.4 #include <stdio.h> main() { char Letter; Letter = 'x'; printf(“nThe letter is %c ”, Letter); return 0; } 17
  • 18. STANDARD OUTPUT • printf Function • prints information to the screen • requires two arguments • control string • conversion specifier Example • double angle = 45.5; • printf(“Angle = %.2f degrees n”, angle); Output: • Angle = 45.50 degrees
  • 19. STANDARD INPUT • scanf Function • inputs values from the keyboard • required arguments • control string • memory locations that correspond to the specifiers in the control string Example: • double distance; • scanf("%lf", &distance);
  • 20. SUMMARY • There are four standard data types can be use in C program which are: • Integer • Float • Char • Void • Everytime you want to use a variable, the declaration must be made • To associate the variables with the data types, you can use standard input and output function 20
  • 21. REFERENCE Hanly, J. R. & Koffman, E. B (2001). C Program Design for Engineers. Addison Wesley Longman. Deitel, P & Deitel H (2008). C How to Program. Pearson Education Inc. 21