Programming basics

I
Programming basics
   Before I explain any   int main()
                           {
    code to you, I            int i;
    would like you to         int sum = 0;

    execute your first         for(i = 0; i<10; i++){
                                   sum += i;
    program by                 }
    copying and
                               printf("Sum = %dn", sum);
    pasting my code.           //system("pause");
                               return 0;
                           }
 Locate the compile button and run
  buttons in your program.
 You may alternatively find the compile
  and run button that executes both at
  once.
 You should notice a black box
  appearing and disappearing very
  quickly. That is because I have allowed
  this code to execute without any pause
  statements.
   Programs typically automatically close
    once the final line of code is reached.

   The line system(“pause”); needs to be
    added to “pause” the program in place

   The system pause should be placed right
    before the return 0; line of any program.
    Return 0 is typically used at the end of a
    program to tell the computer the program
    has ended.
   Code is normally presented omitting the
    system("pause"); statement which
    confuses new programmers. Always
    make a mental note to add it in if you
    are testing new code.
 When you place // before a line of
  code, you comment the code out and
  cause the compiler to skip over the
  code.
 Now you can remove the // before the
  system pause line in the example
  program and run the program again to
  see output. If all is correct, you should
  see the output being Sum = 45.
Programming basics
   I want to draw your attention to the first line:
    int main(){
   This is the beginning of your main function. The
    function ends with the use of }.
   Any time you open a { bracket, you must close it with
    a } bracket.
   As you can see with the main function, you can see
    the entire main function enclosed within the { }
    brackets.
   Additional code is allowed within the brackets. This
    includes code that uses another set of { } as well.
   The last { bracket to be opened is the first one to be
    closed when a } bracket is used.
 The main function is the starting point of
  a program and where a compiler first
  starts to execute your code.
 It is required in order to compile your
  code, therefore it would be a good
  practice to use the following template.
int main(){

     //your new written code goes here

     system("pause");
     return 0;
}
   Our program is going to need a way to hold
    our values
   These values are stored in different types of
    variables.
   Integers, floats, and doubles are the main
    “number” holders of a program.
   A variable in C programming must always be
    declared at the top of the program right under
    int main() { if you want to use the variable in
    your program.
   Unlike some programming languages, you may
    not locally declare a variable anywhere.
 An integer is a number only
  representable in a whole number form.
 Integers: 1,2,3,4,5..
 Not Integers: 1.5, 1.7, 2.5, 3.9, 1003.4...
 Integer math is the calculation between
  two integers. The math is calculated as
  you would normally between any two
  numbers except the decimal value is
  dropped. Ex. 1+3=4, 1+.5=1 , 5/4 = 1
   Double and Float variables allow the use of
    decimal numbers. A float has a smaller
    default precision than a double.
   If you declare a float and then try to store
    the number within the float into a double,
    you may be transferring only part of the
    number.
   A float allows at most about 7 decimal
    places precision.
    A double allows at least 7 places.
   To accurately work beyond 7 decimals you
    may require addition resources.
 I typically use only Doubles when working
  with decimals and will work with only
  Doubles within these tutorials.
 The math calculated with a double or
  float does not use integer math. It would
  be safe to assume the calculated
  answer would be similar to the answer
  given in a math class.
 An integer is declared by typing
  int variablename;
 A float is declared by typing
  float variablename;
 A double is declared by typing
  double variablename;
 The variablename is changeable to
  anything starting with a letter and
  anything that has not been assigned to
  a variable yet.
 Multiple variables of the same type are
  declarable by adding a comma after
  the first variable and then typing the
  second.
 int one, two, three;
 The point of a variable is to eventually
  hold data.
 The variable could be initialized
  immediately with a value.
 int one = 1;
 double duck = 12.5;
   To print out the value a variable is holding
    you use the printf statement
   printf(“The variable one = %d”, one);
   As shown above, the text you want printed
    out is held within the quotation marks. A
    %variabletype is added to signal to the
    computer you want to print out a variable.
    int -> %d float -> %fl double -> %lf
   After the comma, you list the variables in
    order that match up with the %variables
 A double could be printed out but it may
  contain too many decimal places.
 Limit a double by using %.#lf for the
  number of decimal places you want to
  be printed out.
 The key “n” to a computer is
  interpreted as a line break.
 When used in a printf statement, it will
  add a line break into the output.
int main(){

        int one = 5.5;
        float two = 7.5;
        double three = 10.5;

        printf("One equals: %d n", one);
        printf("Two equals: %f n", two);
        printf("Three equals: %lf n ", three);

        three = 15;

        printf("Three equals: %lf ", three);

        system("pause");
        return 0;
}
   Programming Template

   Integers, Floats, and Doubles

   Printf statements
1 de 21

Recomendados

C rules por
C rulesC rules
C rulessykat roy
60 vistas3 diapositivas
Control Structures in Python por
Control Structures in PythonControl Structures in Python
Control Structures in PythonSumit Satam
14K vistas27 diapositivas
Learning R while exploring statistics por
Learning R while exploring statisticsLearning R while exploring statistics
Learning R while exploring statisticsDorothy Bishop
3K vistas12 diapositivas
Conditional and control statement por
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
18.2K vistas19 diapositivas
Ch3 selection por
Ch3 selectionCh3 selection
Ch3 selectionHattori Sidek
929 vistas23 diapositivas
Python Control structures por
Python Control structuresPython Control structures
Python Control structuresSiddique Ibrahim
2.2K vistas62 diapositivas

Más contenido relacionado

La actualidad más candente

Types of Statements in Python Programming Language por
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming LanguageExplore Skilled
368 vistas17 diapositivas
FLOWOFCONTROL-IF..ELSE PYTHON por
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONvikram mahendra
120 vistas8 diapositivas
Python - Control Structures por
Python - Control StructuresPython - Control Structures
Python - Control StructuresLasithNiro
208 vistas24 diapositivas
Chapter 3 por
Chapter 3Chapter 3
Chapter 3Amrit Kaur
119 vistas5 diapositivas
C Programming: Control Structure por
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
14.1K vistas46 diapositivas
Basic computer-programming-2 por
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2lemonmichelangelo
349 vistas19 diapositivas

La actualidad más candente(18)

Types of Statements in Python Programming Language por Explore Skilled
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming Language
Explore Skilled368 vistas
Python - Control Structures por LasithNiro
Python - Control StructuresPython - Control Structures
Python - Control Structures
LasithNiro208 vistas
C Programming: Control Structure por Sokngim Sa
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa14.1K vistas
1584503386 1st chap por thuhiendtk4
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
thuhiendtk4193 vistas
MATLAB programming tips 2 - Input and Output Commands por Shameer Ahmed Koya
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output Commands
Shameer Ahmed Koya1.7K vistas
Basic c# cheat sheet por Ahmed Elshal
Basic c# cheat sheetBasic c# cheat sheet
Basic c# cheat sheet
Ahmed Elshal310 vistas
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++ por Muhammad Hammad Waseem
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++

Destacado

Mca java application projects completed list(is) por
Mca java  application projects completed list(is)Mca java  application projects completed list(is)
Mca java application projects completed list(is)S3 Infotech IEEE Projects
243 vistas2 diapositivas
SHOW104: Practical Java por
SHOW104: Practical JavaSHOW104: Practical Java
SHOW104: Practical JavaMark Myers
5.2K vistas168 diapositivas
Files por
FilesFiles
FilesPurushottam Kumar
271 vistas24 diapositivas
Java practical(baca sem v) por
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)mehul patel
1.1K vistas103 diapositivas
File Uploading in PHP por
File Uploading in PHPFile Uploading in PHP
File Uploading in PHPIdrees Hussain
1.6K vistas6 diapositivas
Java PRACTICAL file por
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL fileRACHIT_GUPTA
12.3K vistas236 diapositivas

Destacado(6)

Similar a Programming basics

Programming For As Comp por
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
764 vistas86 diapositivas
Programming For As Comp por
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
260 vistas86 diapositivas
Tutorial basic of c ++lesson 1 eng ver por
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verQrembiezs Intruder
289 vistas7 diapositivas
Lập trình C por
Lập trình CLập trình C
Lập trình CViet NguyenHoang
921 vistas27 diapositivas
C programming perso notes por
C programming perso notesC programming perso notes
C programming perso notesMelanie Tsopze
295 vistas5 diapositivas
lecture 2.pptx por
lecture 2.pptxlecture 2.pptx
lecture 2.pptxAnonymous9etQKwW
11 vistas102 diapositivas

Similar a Programming basics(20)

Core programming in c por Rahul Pandit
Core programming in cCore programming in c
Core programming in c
Rahul Pandit6.2K vistas
C decision making and looping. por Haard Shah
C decision making and looping.C decision making and looping.
C decision making and looping.
Haard Shah5K vistas
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia... por Dadangsachir WANDA ir.mba
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
C programming por saniabhalla
C programmingC programming
C programming
saniabhalla9.7K vistas
Introduction to Basic C programming 01 por Wingston
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston6.5K vistas
Fundamentals of prog. by rubferd medina por rurumedina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
rurumedina249 vistas
Programming fundamental 02 por Suhail Akraam
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
Suhail Akraam57 vistas

Último

Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... por
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...ShapeBlue
120 vistas13 diapositivas
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive por
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
50 vistas35 diapositivas
"Surviving highload with Node.js", Andrii Shumada por
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
53 vistas29 diapositivas
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... por
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...ShapeBlue
144 vistas12 diapositivas
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T por
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TShapeBlue
112 vistas34 diapositivas
20231123_Camunda Meetup Vienna.pdf por
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
50 vistas73 diapositivas

Último(20)

Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... por ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue120 vistas
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive por Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
"Surviving highload with Node.js", Andrii Shumada por Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays53 vistas
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... por ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue144 vistas
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T por ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue112 vistas
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue por ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue176 vistas
Data Integrity for Banking and Financial Services por Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely78 vistas
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... por ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue123 vistas
Why and How CloudStack at weSystems - Stephan Bienek - weSystems por ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue197 vistas
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue por ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue163 vistas
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... por ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue117 vistas
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... por ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue79 vistas
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue por ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue222 vistas
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... por ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue158 vistas
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... por ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue138 vistas
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... por ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue132 vistas

Programming basics

  • 2. Before I explain any int main() { code to you, I int i; would like you to int sum = 0; execute your first for(i = 0; i<10; i++){ sum += i; program by } copying and printf("Sum = %dn", sum); pasting my code. //system("pause"); return 0; }
  • 3.  Locate the compile button and run buttons in your program.  You may alternatively find the compile and run button that executes both at once.  You should notice a black box appearing and disappearing very quickly. That is because I have allowed this code to execute without any pause statements.
  • 4. Programs typically automatically close once the final line of code is reached.  The line system(“pause”); needs to be added to “pause” the program in place  The system pause should be placed right before the return 0; line of any program. Return 0 is typically used at the end of a program to tell the computer the program has ended.
  • 5. Code is normally presented omitting the system("pause"); statement which confuses new programmers. Always make a mental note to add it in if you are testing new code.
  • 6.  When you place // before a line of code, you comment the code out and cause the compiler to skip over the code.  Now you can remove the // before the system pause line in the example program and run the program again to see output. If all is correct, you should see the output being Sum = 45.
  • 8. I want to draw your attention to the first line: int main(){  This is the beginning of your main function. The function ends with the use of }.  Any time you open a { bracket, you must close it with a } bracket.  As you can see with the main function, you can see the entire main function enclosed within the { } brackets.  Additional code is allowed within the brackets. This includes code that uses another set of { } as well.  The last { bracket to be opened is the first one to be closed when a } bracket is used.
  • 9.  The main function is the starting point of a program and where a compiler first starts to execute your code.  It is required in order to compile your code, therefore it would be a good practice to use the following template.
  • 10. int main(){ //your new written code goes here system("pause"); return 0; }
  • 11. Our program is going to need a way to hold our values  These values are stored in different types of variables.  Integers, floats, and doubles are the main “number” holders of a program.  A variable in C programming must always be declared at the top of the program right under int main() { if you want to use the variable in your program.  Unlike some programming languages, you may not locally declare a variable anywhere.
  • 12.  An integer is a number only representable in a whole number form.  Integers: 1,2,3,4,5..  Not Integers: 1.5, 1.7, 2.5, 3.9, 1003.4...  Integer math is the calculation between two integers. The math is calculated as you would normally between any two numbers except the decimal value is dropped. Ex. 1+3=4, 1+.5=1 , 5/4 = 1
  • 13. Double and Float variables allow the use of decimal numbers. A float has a smaller default precision than a double.  If you declare a float and then try to store the number within the float into a double, you may be transferring only part of the number.  A float allows at most about 7 decimal places precision.  A double allows at least 7 places.  To accurately work beyond 7 decimals you may require addition resources.
  • 14.  I typically use only Doubles when working with decimals and will work with only Doubles within these tutorials.  The math calculated with a double or float does not use integer math. It would be safe to assume the calculated answer would be similar to the answer given in a math class.
  • 15.  An integer is declared by typing int variablename;  A float is declared by typing float variablename;  A double is declared by typing double variablename;  The variablename is changeable to anything starting with a letter and anything that has not been assigned to a variable yet.
  • 16.  Multiple variables of the same type are declarable by adding a comma after the first variable and then typing the second.  int one, two, three;
  • 17.  The point of a variable is to eventually hold data.  The variable could be initialized immediately with a value.  int one = 1;  double duck = 12.5;
  • 18. To print out the value a variable is holding you use the printf statement  printf(“The variable one = %d”, one);  As shown above, the text you want printed out is held within the quotation marks. A %variabletype is added to signal to the computer you want to print out a variable.  int -> %d float -> %fl double -> %lf  After the comma, you list the variables in order that match up with the %variables
  • 19.  A double could be printed out but it may contain too many decimal places.  Limit a double by using %.#lf for the number of decimal places you want to be printed out.  The key “n” to a computer is interpreted as a line break.  When used in a printf statement, it will add a line break into the output.
  • 20. int main(){ int one = 5.5; float two = 7.5; double three = 10.5; printf("One equals: %d n", one); printf("Two equals: %f n", two); printf("Three equals: %lf n ", three); three = 15; printf("Three equals: %lf ", three); system("pause"); return 0; }
  • 21. Programming Template  Integers, Floats, and Doubles  Printf statements