CC213 Programming Applications

Slides:



Advertisements
Similar presentations
11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
TDBA66, VT-03 Lecture - Ch. 21 A complete C-program Display Fig. 2.1 and comment on different things such as Preprocessor directives Header files Identifiers.
1 CS 201 Introduction to C (1) Debzani Deb. 2 Outline Overview of C General form of a C program C Language Elements.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Topic 2 – Introduction to the C Programming Language.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Basic Input/Output and Variables Ethan Cerami New York
CISC 105 – Topic 2 Last Topic Review Name the principle components of a computer. What advantage does assembly language have over machine language? What.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CPCS 202 Chapter 2 – Input/Output
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
1 CSC103: Introduction to Computer and Programming Lecture No 6.
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
C++ Programming: Basic Elements of C++.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CSCI 130 Chapter 3. Variables & Names Variable Declarations: –reserve a storage location in memory –identify the name of the variable –identify the type.
ELE118 Introduction to Programming
Overview of C. C—a high-level programming language developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories. We will discuss: –the elements of a.
9/29/99B-1 CSE / ENGR 142 Programming I Variables, Values, and Types © 1998 UW CSE.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CISC105 – General Computer Science Class 2 – 6/7/2006.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
1 Lecture Three I/O Formatting and Arithmetic Dr. Sherif Mohamed Tawfik.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
SCP1103 Basic C Programming SEM1 2010/2011 Arithmetic Expressions Week 5.
Lecture2.
Arithmetic Expressions
CSCE 206 Structured Programming in C
Topics Designing a Program Input, Processing, and Output
Formatted Input/Output
Chapter 2 - Introduction to C Programming
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Revision Lecture
Chapter 2 Overview of C.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Chapter 2 - Introduction to C Programming
Lecture2.
Formatted Input/Output
By: Syed Shahrukh Haider
Compiled and ready to run Memory Stack /*
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to CS Your First C Programs
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
CS150 Introduction to Computer Science 1
Overview of Computers and C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Lecture3.
CS150 Introduction to Computer Science 1
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2 - Introduction to C Programming
Chapter 2: Overview of C++
Introduction to C Programming
Presentation transcript:

CC213 Programming Applications Week #1

Software Development Method Specify problem requirements Analyze the problem Design the algorithm to solve the problem Implement the algorithm Test and verify the completed program Maintain and update the program

Steps Defined Problem - Specifying the problem requirements forces you to understand the problem more clearly. Analysis - Analyzing the problem involves identifying the problem’s inputs, outputs, and additional requirements. Design - Designing the algorithm to solve the problem requires you to develop a list of steps called an algorithm that solves the problem and then to verify the steps. Implementation - Implementing is writing the algorithm as a program. Testing - Testing requires verifying that the program actually works as desired. Maintenance - Maintaining involves finding previously undetected errors and keep it up-to-date.

Converting Miles to Kilometers Problem: Your boss wants you to convert a list of miles to kilometers. Since you like programming, so you decide to write a program to do the job. Analysis We need to get miles as input We need to output kilometers We know 1 mile = 1.609 kilometers Design Get distance in miles Convert to kilometers Display kilometers

4. Implementation

C Program structure Function Header Function Body

Identifiers Declarations An identifier must consist only of letters, digits, and underscores. An identifier cannot begin with a digit. A C reserved word cannot be used as an identifier. A standard identifier should not be redefined. C compilers are case sensitive. (Rate, rate and RATE are viewed as different identifiers) Valid identifiers: letter1, inches, KM_PER_MILE Invalid identifiers: 1letter, Happy*trout,return

Giving a Value to a Variable

Output Function SYNTAX Examples : printf( format string , print list ) ; Printf(format string); Place holder printf(“That equals %f kilometers. \n”, kms); printf(“enter the distance in miles> ”); printf( “Hello, World?\n“); Escape sequence

Output Function

Input Function SYNTAX Examples : scanf( format string , input list ) ; Place holder scanf(“%lf”, &miles); Ampersand

Input Function

Programming Examples Example-1 Write a program to ask the user for the width and length of a piece of land and then tell him how many orange trees he can grow on it. Given that each orange tree requires 4 m2.

Programming Examples #include <stdio.h> # define one_tree_space 4 int main() { int length,width, area, no_of_tree; printf(“Enter length of the land> ”); scanf(“%d”, &length); printf(“Enter width of the land> ”); scanf(“%d”, &width); area = length * width; no_of_tree = area / one_tree_space; printf(“The available number of trees is %d trees\n”, no_of_tree); return(0); }

Arithmetic Operators Division the result of the division operator depends on the type of its operands if one or both operands has a floating point type, the result is a floating point type. Otherwise, the result is an integer type Examples 11 / 4 has value 2 11.0 / 4.0 has value 2.75 11 / 4.0 has value 2.75 15 / 3 has value 5 16 / 3 has value 5

Arithmetic Operators Modulus the modulus operator % can only be used with integer type operands and always has an integer type result its result is the integer type remainder of an integer division EXAMPLE 3 % 5 = 3 5 % 3 = 2 4 % 5 = 4 5 % 4 = 1 5 % 5 = 0 6 % 5 = 1 7 % 5 = 2 8 % 5 = 3 15 % 6 = 3 15 % 5 = 0