Lecture CSP06
Lecture CSP06
Algorithm
Flow Chart
1
Algorithm
defined as step by step method followed to solve a problem
ie. Well defined sequence of computational steps that’s takes some set
of values as Input and produce some set of values as output
Examples:
1. Start
2. Read radius R
3. Compute V=4/3 π R3
4. Print Volume V
5. End
Algorithm
Algorithm corresponds to solution to a problem that is
independent of any programming languages
Problem
Algorithm
Easy to understand
5
Flow chart symbols :
6
Flow chart for computing Volume of a sphere
Example: Add two numbers entered by user
Algorithm:
Step 1: Start
Step 6: Stop
Example: Calculate area and circumference of a circle
Algorithm:
1. Start
6. Stop
Find whether a given number is even or odd?
Algorithm
1: Start
2 : Read n
3 : when ( n%2 == 0), write “even number"
otherwise write " odd number"
4 : Stop
Convert Temperature from Fahrenheit ( ) to Celsius ( )
Algorithm:
Step 1: Read temperature in Fahrenheit,
Step 3: Print C
To determine Whether a Student Passed the Exam or Not
Algorithm:
1. Start
Grade=(M1+M2+M3+M4)/4
4. Stop
Print number 1 to 20
Algorithm:
1: Initialize X = 0
2: Increment X by 1
3: Print X,
1. Start
2. Input a, b, c
9 . Stop
Find whether a given number is even or odd?
Algorithm
1: Start
2 : Read n
3 : when ( n%2 == 0), write “even number"
otherwise write " odd number"
4 : Stop
Find Sum of N natural numbers
Algorithm
1. Start
1: Start
2: set counter X =0
3: initialize sum =0
4: Read number N
5: X=X+1
6: sum= sum +N
7: Is the X greater than 50
If yes, Display sum: Go to step 8.
If No, Go to step 4
8 : Stop
Factorial of a number
Algorithm: factorial of a number
1 : Start
2 : Read N
8 : Stop
Questions
??
* C Program to find Volume and Surface Area of Sphere */
#include <stdio.h>
int main()
{ float radius, sa,Volume;
printf("\n Please Enter the radius of a Sphere \n");
scanf("%f", &radius);
sa = 4 * 3.14 * radius * radius;
Volume = (4.0 / 3) *3.14 * radius * radius * radius;
return 0;
}