INC 161 , CPE 100 Computer Programming

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 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
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.
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?
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Introduction to C Programming
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. To perform these tasks user friendly.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
1 CSC103: Introduction to Computer and Programming Lecture No 7.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
How to start Visual Studio 2008 or 2010 (command-line program)
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.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
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,
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
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.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
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.
INC 161 , CPE 100 Computer Programming
Chapter 2 - Introduction to C Programming
Decisions Chapter 4.
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
INC 161 , CPE 100 Computer Programming
Introduction to C CSE 2031 Fall /3/ :33 AM.
Introduction to C++ October 2, 2017.
Chapter 2 - Introduction to C Programming
Visit for more Learning Resources
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
INC 161 , CPE 100 Computer Programming
CSCE 206 Lab Structured Programming in C
Chapter 2 - Introduction to C Programming
MSIS 655 Advanced Business Applications Programming
INC 161 , CPE 100 Computer Programming
Chapter 2 - Introduction to C Programming
Selection Statements.
C Programming Getting started Variables Basic C operators Conditionals
SELECTIONS STATEMENTS
Conversion Check your class notes and given examples at class.
INC 161 , CPE 100 Computer Programming
INC 161 , CPE 100 Computer Programming
Programming Concepts and Database
Chapter 2 - Introduction to C Programming
Introduction to C EECS May 2019.
CSCE 206 Lab Structured Programming in C
DATA TYPES There are four basic data types associated with variables:
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
CSCE 206 Lab Structured Programming in C
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Presentation transcript:

INC 161 , CPE 100 Computer Programming Lab 2

Show something on screen printf Tell the program to load the library for printf #include <stdio.h> main () { printf(“Hello World”); } Use commands in the library Put what you want to show in double quote “ ”

Show value of a variable with printf #include <stdio.h> main () { int a = 2; printf(“Hello World %d”,a); } Use special character %d Note: Use special character \n for new line

Special Characters for printf %d replace with int %f replace with float %c replace with char \n new line

Receive input from keyboard scanf Tell the program to load the library for scanf #include <stdio.h> main () { int a; scanf(“%d”,&a); } & indicate pointer (use with scanf) Receive what the user type from keyboard. Interpret it as an integer %d and put in a

Receive two numbers from the keyboard #include <stdio.h> main () { int a,b; scanf(“%d -- %d”,&a,&b); } The user has to type a phrase that match The string in the double quote “ ”.

Task 1 Write a program that calculate the ratio of two numbers. The program asks the user to input two numbers and receive them from the keyboard. Both numbers are point numbers Finally, the program shows the ratio on the screen.

Relational Operators Input: Two numbers Output: True 1 Logic False 0 The relational operators are listed below. Operator Description < less than comparison <= less or equal comparison == equal comparison >= greater or equal comparison > greater comparison != not equal comparison Input: Two numbers Output: True 1 Logic False 0

Arithmetic Operator 2 + 3 = 5 Relational Operator 2 < 3 = 1 (True) Output Number Output Logic Note: = and == are totally different

Logical Operators Input: True 1 Logic False 0 Output: True 1 There are three logical operators in C: 1) ! --- logical negation 2) && --- logical AND 3) || --- logical OR x y !x x && y x || y 1 Input: True 1 Logic False 0 Output: True 1 Logic False 0

Please write these logic in C language -2 < x < 5 x is either 3 or 5 (x > -2)&&(x < 5) (x == 3)||(x == 5)

If Command If Statements The syntax for an if-statement is as follows: if(expression) statement The statement is executed if the expression is unequal to 0. If there are many commands, they need to be placed inside { } Example: int i = 1; if(i) printf(“Single command”); if(i > 0) { i = 2; printf(“Multiple commands”); }

Task 2 Write a program that calculate an absolute value of a number and print the result on screen. Receive 1 integer from the keyboard Calculate the absolute value Show the result on screen Hint: For positive value, absolute = itself For negative value, absolute = - itself

Extra Tasks Write a program that calculate the last digit (least significant digit) of an integer number. e.g. last digit of 438 is 8 last digit of 37 is 7