Presentation is loading. Please wait.

Presentation is loading. Please wait.

Type casting Algorithm & flowchart

Similar presentations


Presentation on theme: "Type casting Algorithm & flowchart"— Presentation transcript:

1 Type casting Algorithm & flowchart

2 Find more functions in C
Please look at

3

4 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.

5 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.

6 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.

7 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; }

8 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; }

9 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.

10 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!

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

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

13 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

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

15 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); }

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

17 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.

18 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.

19 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'.

20 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.

21 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.

22 Draw a flowchart to add two numbers entered by user

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


Download ppt "Type casting Algorithm & flowchart"

Similar presentations


Ads by Google