Programming Fundamentals Lecture #4 Overview of Computer Programming

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Chapter 2 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.
Introduction to C Programming
Chapter 2 Introduction to C Programming
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Chapter 2 Introduction to C Programming Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 CSC103: Introduction to Computer and Programming Lecture No 6.
VARIABLES & CONSTANTS. Objective By the end of the lesson students should be able to:  Define a constant  Define a variable  Understand the rules for.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
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.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
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.
Chapter # 2 Part 2 Programs And data
A variable is a name for a value stored in memory.
Introduction to C Programming
ARITHMETIC IN C Operators.
Programming Fundamentals
Chapter 2 - Introduction to C Programming
ICS103 Programming in C Lecture 3: Introduction to C (2)
Programming Fundamentals Lecture #7 Functions
Lecturer CS & IT Department UOS MBDIN
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Introduction to C Programming
Programming Fundamentals Lecture #6 Program Control
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Chapter 2 - Introduction to C Programming
Chapter 2 Introduction to C Programming
Chapter 2 - Introduction to C Programming
INPUT & OUTPUT scanf & printf.
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
1) C program development 2) Selection structure
Chapter 2 - Introduction to C Programming
Programming Fundamentals Lecture #3 Overview of Computer Programming
Fundamentals of visual basic
Chapter # 2 Part 2 Programs And data
Introduction to C Programming
C Programming Pointers
Data Structures & Algorithms
Chapter 2 - Introduction to C Programming
DATA TYPES There are four basic data types associated with variables:
Introduction to C Programming
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to C Programming
Getting Started With Coding
Presentation transcript:

Programming Fundamentals Lecture #4 Overview of Computer Programming Junaid Hassan Lecturer CS & IT Department UOS MBDIN junaidte14@gmail.com

C Program (Defining Variables and Sum) Define 2 variables, sum their values and print sum on the screen

C Program (Defining Variables and Sum) In line printf(“Sum is %d”, sum); %d is called as conversion specifier. %d indicates that the data should be an integer. The letter d stands for decimal integer. This placeholder is ultimately filled by the value of variable named as ‘sum’.

C Program (Taking Input From User) Take 2 input integer numbers from user, sum these number and print the result on the screen

C Program (Taking Input From User) Everything in this program is explained in previous slides except following line: scanf("%d", &number1); We already discussed that %d is a conversion specifier which says that it will hold data of the type decimal integer Whereas ampersand (&) is called as address operator in C. Ampersand (&) when combined with variable name (number1), tells scanf the location (or address) in memory at which the variable number1 is stored Use of ampersand will become clear when we will study pointers in chapter 7

Memory Concepts Variables we defined in our previous code examples actually correspond to locations in the computer memory Every variable has a name, type and value For example when scanf(“%d”, &number1); is executed, the value entered by the user is stored into a memory location and we have assigned a name to that location i.e number1. Similarly value of each variable is stored into a different memory location and when we need to get the value stored at that memory location, we use the variable name When we assign new value to a variable then previous value is replaced by that new value. In other words previous value stored at that memory location is destroyed and is replaced by the new value

C programs can perform arithmatic operations using following symbols: Arithmatic in C C programs can perform arithmatic operations using following symbols:

Precedence of arithmatic operators: Arithmatic in C Precedence of arithmatic operators:

Example of precedence of arithmatic operators: Arithmatic in C Example of precedence of arithmatic operators:

Decision Making: Equality and Relational Operators In C Program, sometime we need to make decisions by comparing variable values. In order to make decisions in C programming, we use equality and relational operators. If Statment is used to make a decision whether a condition is true or false Conditions in if statement are formed using equality and relational operators (shown in below table)

Decision Making: Equality and Relational Operators See Example Code

Keywords / Reserved Words in C Keywords / reserved words have special meaning to compiler, so don’t use these keywords as your variable names in order to avoid conflicts/fatal errors. Keywords/reserved words used in C are mentioned in below table: