Type casting Algorithm flowchart Find more functions in

  • Slides: 23
Download presentation
Type casting Algorithm & flowchart

Type casting Algorithm & flowchart

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

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

C Library – header file: <math. h> Function Description double acos(double x) Returns the

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 atan 2(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)

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 log 10(double x) Returns the common 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. logarithm (base-10

var++ vs. ++var � x++ means Increment x after this line and ++x means

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 preincrements the value first and then uses it in context.

var++ vs. ++var(cont. ) #include <stdio. h> int main() { int X=5; int Y=5;

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

var++ vs. ++var(cont. ) #include <stdio. h> int main() { int X=5; int Y;

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

Type Casting In C � Type Casting In C Language. Type casting is a

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

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) int + (f*d) -

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

Type casting in initialization � May lose the data! char ch; int i; float

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 char signed char If char>127, destination

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

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

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

Example: Casting types #include <stdio. h> int main() { int num; int a=10, b=3;

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 %fn", c); c=(float)a/b; printf("the result with casting %fn", 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

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

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.

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

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

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

Flowchart/Decision-Conditional � Decision object is represented as a Diamond. This object is always used

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 a flowchart to add two numbers entered by user

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

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