LAB 2 : PROBLEM SOLVING TECHNIQUES, ALGORITHM: PSEUDO CODE AND FLOWCHART LAB INTRODUCTION Prepared by: Cik Noor Syazana bt Arshad.

Slides:



Advertisements
Similar presentations
Standard I/O Lesson Outline
Advertisements

Standard I/O Lesson CS1313 Spring Standard I/O Lesson Outline 1.Standard I/O Lesson Outline 2.Output via printf 3.Placeholders 4.Placeholders for.
Principles of Programming Chapter 3 Fundamental of C Programming Language and Basic Input/Output Function 1 NI S1 2009/10.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
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.
Software Development Method & C Language Elements H&K Chapter 1-2
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.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Principles of Programming - NI Chapter 3 Fundamental of C Programming Language and Basic Input/Output Function.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
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 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Yu Yuanming CSCI2100B Data Structures Tutorial 3
C Tokens Identifiers Keywords Constants Operators Special symbols.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Input, Output, and Processing
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Week 2 Introduction to Computer Programming/ C Programming Language 1 EKT120: Computer Programming.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
C OMPUTER P ROGRAMMING 1 Assignment. A SSIGNMENT We have used gets to input a value into variable The second way to give a variable a value is known as.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
UniMAP Sem II-10/11EKT120: Computer Programming1 Week 1 – Introduction to Computer and Algorithm (Part 2)‏
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
UniMAP Sem I-09/10EKT150: Computer Programming1 Week 2 – Introduction to Computer and Algorithm.
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 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
C Language Elements Preprocessor Directives # (sign for preprocessor directive commands) #include Standard header file (.h) Library.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Lecture2.
Numbers in ‘C’ Two general categories: Integers Floats
Topics Designing a Program Input, Processing, and Output
Zhang Hongyi CSCI2100B Data Structures Tutorial 3
Formatted Input/Output
ICS103 Programming in C Lecture 3: Introduction to C (2)
Lecture2.
Formatted Input/Output
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Engr 0012 (04-1) LecNotes
Introduction to CS Your First C Programs
INPUT & OUTPUT scanf & printf.
CSCE 206 Lab Structured Programming in C
Programming Funamental slides
Conversion Check your class notes and given examples at class.
Lecture3.
CS150 Introduction to Computer Science 1
WEEK-2.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Session 1 – Introduction to Computer and Algorithm (Part 2)‏
CSCE 206 Lab Structured Programming in C
Presentation transcript:

LAB 2 : PROBLEM SOLVING TECHNIQUES, ALGORITHM: PSEUDO CODE AND FLOWCHART LAB INTRODUCTION Prepared by: Cik Noor Syazana bt Arshad

The printf function Prepared by: Cik Noor Syazana bt Arshad printf Display message on screen printf(“Welcome to UNIMAP”); Directly display message Use double quote (“ ”) printf (“The expense is = %f ”,fExpense); Display dynamic value after data processing % - to indicate location to print variable value f – float (data type)

Formatted Output with “printf” #include int main (void) { int iMonth; float fExpense, fIncome; iMonth = 12; fExpense = 111.1; fIncome = ; printf (“The Month is %4d and the Expense is RM%9.2f\n”,iMonth, fExpense); } Prepared by: Cik Noor Syazana bt Arshad Declaring variable (iMonth) to be integer Declaring variables (fExpense and fIncome) to be real Assignment statements store numerical values in the memory cells for the declared variables Correspondence between variable names and %...in string literal ‘, ’ separates string literal from variable names

Formatted Output with printf-cont printf (“The Month is %4d and the Expense=RM %9.2f \n”,iMonth, fExpense); %4d refer to variable iMonth value (decimal number format) %9.2f refer to variable fExpense value. (floating point format) The output of printf function will be displayed as Prepared by: Cik Noor Syazana bt Arshad

The scanf function scanf accept user input from keyboard scanf (“%f”,&fExpense); %f -float (data type) %f must be in double quote “” Symbol ‘&’ must be used with scanf command Prepared by: Cik Noor Syazana bt Arshad

Formatted Output with “printf & scanf” #include int main (void) { int iMonth; float fExpense, fIncome; printf(“Please enter month”); scanf (“%d”,&iMonth); printf(“Please enter the expense and income”); scanf (“%f%f”,&fExpense,&fIncome); printf (“The Month is %4d and the Expense is RM%9.2f\n”, iMonth, fExpense); } Prepared by: Cik Noor Syazana bt Arshad Declaring variable (iMonth) to be integer Function scanf reads value typed on keyboard Function scanf reads the first value as fExpense and the second value as fIncome

Prepared by: Cik Noor Syazana bt Arshad Formatted input with scanf-cont

Data types printf integer - %d long integer - %ld float - %f double - %f character - %c string - %s scanf integer - %d long integer - %ld float - %f double - %lf character - %s string - %s Prepared by: Cik Noor Syazana bt Arshad

Escape sequence \n Next line To display output in next line \a Bell sound when execute \t Horizontal tab To add space between output % Placeholder To indicate location to print variable value Prepared by: Cik Noor Syazana bt Arshad

How to print a line? Command printf(“Welcome to UNIMAP”); printf(“ ”); Display Welcome to UNIMAP Prepared by: Cik Noor Syazana bt Arshad

Algorithm-Basic symbols in a flowchart Start/End Process Input/Output Decision Flow direction Connector

Prepared by: Cik Noor Syazana bt Arshad Q: Write a program to convert distance in meter(m) to centimeter(cm)...‏ Start Get input or distance value in m perform conversion from m to cm using formula: cm=100*m print output or distance value in centimeter (cm) End

Pseudo code Begin Get distance value in meter (m) Perform conversion from m to cm using formula: cm=100* m Print distance value in centimeter (cm) End Prepared by: Cik Noor Syazana bt Arshad

Program Coding #include int main () { // variables declaration float fcm,fm; // to display message printf(“\nProgram to convert distance from meter to centimeter”); Prepared by: Cik Noor Syazana bt Arshad

Program Coding (Continued) printf (“\n\nPlease enter the value of distance in meter: ”); scanf(“%f”, &fm); fcm = 100*fm; printf(“\nThe value of distance in centimeter is %5.2f cm\n,fcm); return 0; } //end of main Prepared by: Cik Noor Syazana bt Arshad

Q: Write a program to calculate the volume of a cylinder Start Get radius and height values in inches perform conversion from inches to cm using formula: 1 inches=2.54cm print output or cylinder volume in centimeter cubed (cm 3 ) End Calculate volume of a cylinder Prepared by: Cik Noor Syazana bt Arshad

Pseudo code Begin Get radius and height values in inches Calculate volume of cylinder using formula volume=pi*radius 2 *height Perform conversion from inches to cm using formula: 1inch=2.54cm Print volume of cylinder in cm 3 End Prepared by: Cik Noor Syazana bt Arshad

Program Coding #include int main () { // variables declaration const double PI= ; double dVolume; float fR,fH; // to display message printf(“\nProgram to calculate the volume of a Cylinder\n”); Prepared by: Cik Noor Syazana bt Arshad

Program Coding (Continued) printf (“\nPlease enter the value of radius and height in inches:\n ”); scanf(“%f%f”, &fR,&fH); dVolume= PI*fR*2.54*fR*2.54*fH*2.54; printf(“\nThe volume of a cylinder in centimeter cubed is %7.2f cm\n”,dVolume); return 0; } //end of main Prepared by: Cik Noor Syazana bt Arshad