Type casting Algorithm & flowchart

Slides:



Advertisements
Similar presentations
Flow Control Analysis & Design Tool: Flowcharts
Advertisements

Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Functions. COMP104 Lecture 13 / Slide 2 Review of Array: Bubble Sort for (j=0; j List[j+1]) swap(List[j], List[j+1]); }
Introduction to Java Programming, 4E Y. Daniel Liang.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
1 Chapter 5 Methods. 2 Introducing Methods A method is a collection of statements that are grouped together to perform an operation.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Topic 2A – Library Functions and Casting. CISC 105 – Topic 2A Functions A function is a piece of code which performs a specific task. When a function.
1 Topic 04 Methods Programming II/A CMC2522 / CIM2561 Bavy Li.
 2000 Prentice Hall, Inc. All rights reserved. Functions in C Outline 1Introduction 2Program Modules in C 3Math Library Functions 4Functions 5Function.
Algorithm & Flowchart.
CHAPTER 8 OPERATORS AND EXPRESSIONS IN C++. OPERATORS The operations (specific task) are represented by operators and the objects of the operation(s)
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Functions in C Outline 1Introduction 2Program Modules in C 3Math Library Functions 4Functions 5Function Definitions 6Function Prototypes 7Header Files.
1 Last of the basics Controlling output Overflow and underflow Standard function libraries Potential pitfalls of getting information with cin Type casting.
Lecture 5 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Chapter 5: Methods 1. Objectives To declare methods, invoke methods, and pass arguments to a method (§ ). To use method overloading and know ambiguous.
Chapter 4 Methods F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters F Pass by Value F Overloading Methods F Method Abstraction.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 4 Mathematical Functions, Characters,
Week 2 - Wednesday.  What did we talk about last time?  C compilation model  Lab 1.
OPERATORS.
Week 2 - Friday.  What did we talk about last time?  Base systems  C literals  Representations in memory.
Basic problem solving CSC 111.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 Java Library Lecture 9 by Dr. Norazah Yusof. 2 Java Library Java has pre-defined classes that consist of the basic language classes in Java (organized.
Review 1 Computers and Programming I Dr. Ming Zhang Tel: (757) Fax: (757) Office: Gosnold 217b Subject Overview.
Recap……Last Time [Variables, Data Types and Constants]
Chapter 4: Methods Method Structure Method Structure Declaring Methods Declaring Methods Calling Methods Calling Methods Passing Parameters Passing Parameters.
Operators and Expressions. Introduction C operators can be classified into a number of categories 1.Arithmetic(+, -, *, /, %) 2.Relational (, >=, ==,
Operators and Expressions
Chapter 5 Methods F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters F Pass by Value F Overloading Methods F Method Abstraction.
Chapter 4 Mathematical Functions, Characters, and Strings 1.
Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
Variables, Operators, and Expressions
Chapter 4 Mathematical Functions, Characters, and Strings
Algorithm: procedure in terms of
A451 Theory – 7 Programming 7A, B - Algorithms.
Mathematical Functions
Introduction to Flowcharting
INC 161 , CPE 100 Computer Programming
INSPIRING CREATIVE AND INNOVATIVE MINDS
Tokens in C Keywords Identifiers Constants
Chapter 4 Mathematical Functions, Characters, and Strings
TMF1414 Introduction to Programming
Be A programmer in Steps
Functions.
Chapter 3 Methods.
Introduction to C Programming
Chapter 5 – Part 2 Methods Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
How to develop a program?
Chapter 4: Mathematical Functions, Characters, and Strings
PROBLEM SOLVING CSC 111.
More about Numerical Computation
Structured Program
Loops in C.
CSI 101 Elements of Computing Spring 2009
Introduction to Algorithms and Programming
Lectures on Numerical Methods
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
Chapter 5 Methods.
CST-115 Introduction to Computer Programming
Developing a Program.
Chapter 4 Methods Introducing Methods Declaring Methods
Assignment Operators Topics Increment and Decrement Operators
Functions in C Math Library Functions Functions Function Definitions
Ch 5 : Mathematical Functions, Characters, and Strings
Presentation transcript:

Type casting Algorithm & flowchart

Find more functions in C Please look at http://www.cplusplus.com/

C Library – header file:<math.h> Function Description double acos(double x) Returns the arc cosine of x in radians. double asin(double x) Returns the arc sine of x in radians. double atan(double x) Returns the arc tangent of x in radians. double atan2(doubly y, double x) Returns the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant. double cos(double x) Returns the cosine of a radian angle x. double cosh(double x) Returns the hyperbolic cosine of x. double sin(double x) Returns the sine of a radian angle x. double sinh(double x) Returns the hyperbolic sine of x. double tanh(double x) Returns the hyperbolic tangent of x.

C Library – header file:<math.h> (cont.) Function Description double exp(double x) Returns the value of e raised to the xth power. double log(double x) Returns the natural logarithm (base-e logarithm) of x. double log10(double x) Returns the common logarithm (base-10 logarithm) of x. double pow(double x, double y) Returns x raised to the power of y. double sqrt(double x) Returns the square root of x. double ceil(double x) Returns the smallest integer value greater than or equal to x. double fabs(double x) Returns the absolute value of x. double floor(double x) Returns the largest integer value less than or equal to x. double fmod(double x, double y) Returns the remainder of x divided by y.

var++ vs. ++var x++ means Increment x after this line and ++x means Increment x before this line. With i++, it's called postincrement, and the value is used in whatever context then incremented; ++i is preincrement increments the value first and then uses it in context.

var++ vs. ++var(cont.) #include <stdio.h> int main() { int X=5; int Y=5; printf("The value of ++X: %d",++X); printf("\nThe value of X is: %d\n",X); printf("\nThe value of Y++: %d",Y++); printf("\nThe value of Y is: %d",Y); return 0; }

var++ vs. ++var(cont.) #include <stdio.h> int main() { int X=5; int Y; Y=X++; printf("\nThe value of Y is: %d",Y); printf("\nThe value of X is: %d",X); return 0; }

Type Casting In C  Type Casting In C Language. Type casting is a way to convert a variable from one data type to another data type. For example, if you want to store a long value into a simple integer then you can type cast long to int.

Type Casting In arithmetic If an operand is long double, the other operand is converted to long double! Else if an operand is double, the other operand is converted to double! Else if an operand is float, the other operand is converted to float! Else if an operand is unsigned long, the other operand is converted to unsigned long! Else if an operand is long, the other operand is converted to long! Else if an operand is unsigned int, the other operand is converted to unsigned int!

char ch; int i; float f; double d; result= (ch/i) + (f*d) - (f+i); int double float int double float double double double

Type casting in initialization May lose the data! char ch; int i; float f; double d; … ch=i; i=f; f=ch; f=i;

Type casting in initialization (cont.) source destination The lost data char signed char If char>127, destination will be negative short int 8 most significant bits int 8 most significant bits (16 bits system) 24 most significant bits(32bits system) long int 24 most significant bits No lost data! (16 bits system) 16 most significant bits(32 bits system) 16 most significant bits float The mantissa part double Precision lost & the data is rounded long double

Type casting in initialization (cont.) sizeof(int) sizeof(char)

Example: Casting types #include <stdio.h> int main() { int num; int a=10,b=3; float c; c=a/b; printf("the result without casting %f\n",c); c=(float)a/b; printf("the result with casting %f\n",c); return 0; } #include <stdio.h> int main() { float a=10; int b=3; float c=a/b; printf("%f",c); printf("%d", a/b); }

Algorithm a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.

Flowchart A flowchart is a type of diagram that uses an algorithm, workflow or process, showing the steps as boxes of various kinds, and their order by connecting them with arrows. This diagrammatic representation illustrates a solution model to a given problem.

Flowchart/Terminal-Terminator The terminator is used to show where your flow begins or ends. Ideally, you would use words like 'Start', 'Begin', 'End' inside the terminator object to make things more obvious.

Flowchart/Process - Rectangle Flowchart Process object is used to illustrate a process, action or an operation. These are represented by rectangles; and the text in the rectangle mostly includes a verb. Examples include 'Edit video', 'Try Again', 'Choose your Plan'.

Flowchart/Flow line & Input/Output Flow line: A line that connects the various symbols in an ordered way Input/Output: Used for input and output operation.

Flowchart/Decision-Conditional Decision object is represented as a Diamond. This object is always used in a process flow to as a question. And, the answer to the question determines the arrows coming out of the Diamond. This shape is quite unique with two arrows coming out of it. One from the bottom point corresponding to Yes or True and one from either the right/left point corresponding to No or False. The arrows should be always labelled to avoid confusion in the process flow.

Draw a flowchart to add two numbers entered by user

Draw flowchart to find the largest among three different numbers entered by user