Let’s start from the beginning

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

ARDUINO CLUB Session 1: C & An Introduction to Linux.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Lecture 2 Introduction to C Programming
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
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.
Computer Science 210 Computer Organization Introduction to C.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Programming With C.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
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.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
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 Programming
Khalid Rasheed Shaikh Computer Programming Theory 1.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
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.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
PHP using MySQL Database for Web Development (part II)
Introduction to C Topics Compilation Using the gcc Compiler
Basic concepts of C++ Presented by Prof. Satyajit De
UMBC CMSC 104 – Section 01, Fall 2016
CSCE 206 Structured Programming in C
Computer Science 210 Computer Organization
INC 161 , CPE 100 Computer Programming
Chapter 2 - Introduction to C Programming
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.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
C programming language
Introduction to C Topics Compilation Using the gcc Compiler
C Basics.
Chapter 2 - Introduction to C Programming
Imperative Programming
Arrays in C.
Administrative things
Computer Science 210 Computer Organization
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
C Stuff CS 2308.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to CS Your First C Programs
Chapter 2 - Introduction to C Programming
1) C program development 2) Selection structure
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Chapter 2 - Introduction to C Programming
Revision.
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
C programming Language
Functions.
Introduction to C Topics Compilation Using the gcc Compiler
Programs written in C and C++ can run on many different computers
Functions continued.
Chapter 2 - Introduction to C Programming
Arrays.
Introduction to C EECS May 2019.
DATA TYPES There are four basic data types associated with variables:
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
EECE.2160 ECE Application Programming
Introduction to C Programming
Presentation transcript:

Let’s start from the beginning

The C language Dates back to 1972 with newer versions of it still being developed Influential to most of the widely used languages today Has an objective sibling C++ According to TIOBE index, #2 used language in the world (#3 is C++) General purpose language Compiled from source code Works on almost anything Does not contain magic Basic, but fast 2018 Risto Heinsar

Use cases Embedded systems Hardware drivers Operating system kernels (Linux, Windows, Mac OS, Android, iOS) Web servers (nginx, apache) Database management systems (Oracle, MySQL, PostgreSQL, MariaDB) Many modern languages use modules written in C Etc 2018

Being stylish – blue.pri.ee/ttu/coding-style You should always save the file with .c extension before writing the code – this way the editor will help you write it Look into the style guide provided The style guide is important for both of us – using a good style makes you look professional and makes it easier to read and fix your code Comment your code – this way we will understand, you will remember and your friend can help Indent before, not after – why work to indent and make your code readable, let the IDE do it for you and not worry about it 2018

The code (hello.c) 2018

Some properties of the C language Variable types must be set and declared before using them. It’s often recommended to do it in the beginning of the function. Do not use uninitialized variables Most of the lines end with a semicolon, but not all! For storing multiple characters (text), an array of characters must be created for which we need to specify a size Text must always have room for 1 extra character (terminator) For reading a single value (e.g. number), ampersand (&) symbol must precede the variable name. This is not the case for output. Comments can be made in two ways // they can be preceded by two forward slashes /* or they can be between the forward slash and asterisk symbols */ 2018

Our program #include <stdio.h> – this line includes the standard input and output library to your program (for functions printf(), scanf() e.t.c.) int main(void) main – this is the first part to run (and looked for) when executing your program int – when your codes finishes execution, an integer must be returned void – indicates, that nothing will be passed to the program when executing return 0 – this returns a value to whatever called the problem and in this case, ending the program. Code 0 indicates that no errors occurred during this and the program finished successfully. 2018

Basic data types Data Data type Format Examples Integers int %d 1, 3, -55, 0 Floating point numbers float, double %f, %g 1.2, -5.5, 1.0, 0.0, -0.0, 5.2e3, 10.332f Character char %c ‘a’, ‘x’, ‘-’, ‘ ‘ Text, string char [] %s „Hello“, „Lorem ipsum“ Truth value bool True (1), false (0) 2017 Risto Heinsar

Input and output <stdio.h> is the standard input-output library This is only one of the libraries that we’ll use, many more to come printf() – used for formatted printing into the console printf("Hello! \n"); scanf() – used to get formatted user input from console scanf("%s", name); %s – format for text scanf("%d", &birthYear); %d – format for integer Don’t be afraid to experiment and look further http://www.cplusplus.com/reference/cstdio/ 2018

Algorithms An algorithm is a step-by-step guide to solving a problem They can be for real-word situations like customer-administrator relations, but are mostly used in mathematics and IT. Algorithms help to define processes that can be understood by multiple parties in the same way UML activity diagrams mostly consist of actions, decisions, forks and joins (for parallel activities), comments, initial and end nodes. Actions used in this program: printing, reading input and calculations. No decisions, forks or joins were used in this program. https://blue.pri.ee/ttu/resources/introduction-to-algorithms-and-uml/ 2018

Hello.c algorithm 2018