Beruflich Dokumente
Kultur Dokumente
2 Program Development
Exercise
𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 26 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation
𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 27 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂
𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 28 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂
−𝒃 + 𝒃𝟐 − 𝟒𝒂𝒄 −𝒃 − 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏 = 𝒂𝒏𝒅 𝒙𝟐 =
𝟐𝒂 𝟐𝒂
𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 29 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation Discriminator
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂
−𝒃 + 𝒃𝟐 − 𝟒𝒂𝒄 −𝒃 − 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏 = 𝒂𝒏𝒅 𝒙𝟐 =
𝟐𝒂 𝟐𝒂
𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 30 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation Discriminator
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂
−𝒃 + 𝒃𝟐 − 𝟒𝒂𝒄 −𝒃 − 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏 = 𝒂𝒏𝒅 𝒙𝟐 =
𝟐𝒂 𝟐𝒂
𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄
𝒊𝒇 𝑫 < 𝟎 𝒙𝟏 𝒂𝒏𝒅 𝒙𝟐 𝒂𝒓𝒆 𝑰𝒎𝒂𝒈𝒊𝒏𝒂𝒓𝒚
𝒊𝒇 𝑫 > 𝟎 𝒙𝟏 𝒂𝒏𝒅 𝒙𝟐 𝒄𝒂𝒏 𝒃𝒆 𝑪𝒂𝒍𝒄𝒖𝒍𝒂𝒕𝒆𝒅
𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 31 Higher Technological Institute
Problem Definition and Analysis
o How information is processed to give the required
output ?
𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 32 Higher Technological Institute
Algorithms and Flowcharts
Flow direction
𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂
𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂
𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂
𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄
YES NO
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂
𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄
YES NO
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂
𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄
YES NO
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂
Up to Rs 35000 Nil
From Rs 35001 20% of income
To Rs 60000 in Excess of Rs 35000
From Rs 60001 Rs 5000 + 30% of income in
To Rs 120000 Excess of Rs 60000
Rs 23000+ 40% of income in
More than Rs 120000
Excess of Rs 120000
𝒏! = 𝒏 × 𝒏 − 𝟏 × 𝒏 − 𝟐 … × 𝟑 × 𝟐 × 𝟏
C Programming 57 Higher Technological Institute
Example 2.8
Draw flow chart to compute the factorial:
n! = n*(n-1)*(n-2)* … * 3 * 2 * 1
Example 2.7
Draw flow chart to compute the factorial:
10! = 10*9*8* … * 3 * 2 * 1
Example .6
Draw flow chart to generate square roots of the series:
1, 4, 9, 16, 25, 36, 49, 64, 81, 100
Algorithms
o Assembly Language.