2.1 First C Program. First Program Open visual studio, click new file Save as “programName.c” – Program must start with letter and have no spaces – Must.

Slides:



Advertisements
Similar presentations
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
Software Development Method & C Language Elements H&K Chapter 1-2
Structure of a C program
How to Create a Java program CS115 Fall George Koutsogiannakis.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Introduction to Perl. How to run perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Your program/script.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Hello AP Computer Science!. What are some of the things that you have used computers for?
Chapter 3 Getting Started with C++
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Agenda Review Unix Review Algorithms Your first program Compiling programs What are functions? What is Object Oriented Programming? Variables Data Types.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Web Programming Basics of HTML. HTML stands for Hyper Text Mark-up Language A mark-up language is different than those that you have learned before in.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Programming With C.
Documentation and Comments. What’s a comment? A comment is a simple form of documentation. Documentation is text that you the programmer write to explain.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
EPSII 59:006 Spring Introduction to C More Administrative Details The C Programming Language How a computer processes programs Your first C program.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Chapter 2: Java Fundamentals
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
1 Structure of a C Program (continued) Presentation original from Dr. Turner’s class USF - COP C for Engineers Summer 2008.
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
Agenda Computer Languages How to Write a Simple C Program
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
CSC 110 – Intro to Computing - Programming
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Programming Language Basics. What is a Programming Language? “A computer, human-created language used to write instructions for a computer.” “An artificial.
Lecture 3: Getting Started & Input / Output (I/O)
CMPT 201.
Pamela Moore & Zenia Bahorski
Chapter 2, Part I Introduction to C Programming
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
Introduction to C Language
Intro to Java.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Writing Methods.
Number and String Operations
Programming Language Basics
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Getting Started With Coding
Presentation transcript:

2.1 First C Program

First Program Open visual studio, click new file Save as “programName.c” – Program must start with letter and have no spaces – Must end with.c (visual studio will autoset.c if you select file type – There can be no spaces in the name!!!!

Header files At the top of any program, you must include “header files” These files are subprograms that tell the computer how to use built in features of the language. Ex:,,

First Program First type in header files

Main Function Every Program in C has something called a main function Basically tells the computer where to start executing code. Goes after the header files

Int main(void) int main(void) Int we’ll talk about later Main tells computer this is where to start Void tells computer not to expect any inputs at very beginning.

Int main(void)

Curly Brace Whenever we want to enclose chunks of code, we always put the curly brace around them. In this case, we want to section off the main chuck of code.

Main Inside the main function we start writing the instructions for the computer Computer executes code one after the other in order

printf() printf() is a built in feature of C that was activated when we included stdio.h into the code Its function is to print things to the screen

Printf()

Double quote “hello” Quotes needed because we just want to print whatever is inside, no special operations or variables

; Ever separate execeuted line in C needs to be ended with semi colon If you forget semi colon the program DOESN’T WORK Imagine a program with 500 lines of code and you forget one semi color…..= frustrating

Return 0;

return 0; Most chucks of code, from now on will be called Functions usually return some type of value. In our simple program, were not creating a special value so we will return 0 which in computer language is a sign of successful execution.

First Program Click Save Open VS Command Prompt Navigate using “cd” to folder that holds your.c file Type “cl firstProgram.c” +Entr Type “firstProgram”+Entr Viola

Compiler Source code -> Machine Code Needs to recompile after every change in program Input.c file -> output.exe file

Program Documentation and Formatting

Formatting All functions are indented from their start Documentation is usually parallel to each other Separate header files, different functions, variables, and other types of code.

Documenting Required for full marks and in real world Helps reader/programmer understand code Two ways to document code – /* ……… */ is one way that omits everything inside slashes from compiler – // omits everything on that line from compiler

Things to Remember Always include ; when needed Always document Always save as.c file Keep track of opening and closing brackets Formatting/Documenting makes things much easier to debug

Assignment Create another program (brand new not just last program copy and pasted) that says “I am now a programmer” but this time try to : – return 1 – Forget ; – Forget to close bracket – Forget header file – Spell printf wrong – Forget to include closing */

Reading Pg for further description of initial C code