Beruflich Dokumente
Kultur Dokumente
Applications
Week #1
Software Development
Method
1.
2.
3.
4.
5.
6.
Steps Defined
1. Problem - Specifying the problem requirements
forces you to understand the problem more clearly.
2. Analysis - Analyzing the problem involves identifying
the problems inputs, outputs, and additional
requirements.
3. Design - Designing the algorithm to solve the
problem requires you to develop a list of steps
called an algorithm that solves the problem and
then to verify the steps.
4. Implementation - Implementing is writing the
algorithm as a program.
5. Testing - Testing requires verifying that the program
actually works as desired.
6. Maintenance - Maintaining involves finding
previously undetected errors and keep it up-todate.
3
Converting Miles to
Kilometers
3. Design
4. Implementation
C Program structure
Function Header
Function Body
Identifiers Declarations
Output Function
SYNTAX
printf( format string , print list ) ;
Printf(format string);
Examples :
Place holder
Escape sequence
9
Output Function
10
Input Function
SYNTAX
scanf( format string , input list ) ;
Examples :
Place holder
scanf(%lf, &miles);
Ampersand
11
Input Function
12
Programming Examples
Example-1
Write a program to ask the user for the width
and length of a piece of land and then tell him
how many orange trees he can grow on it.
Given that each orange tree requires 4 m2.
13
Programming Examples
#include <stdio.h>
# define one_tree_space 4
int main()
{
int length,width, area, no_of_tree;
printf(Enter length of the land> );
scanf(%d, &length);
printf(Enter width of the land> );
scanf(%d, &width);
area = length * width;
no_of_tree = area / one_tree_space;
printf(The available number of trees is %d
trees\n, no_of_tree);
}
return(0);
14
Arithmetic Operators
Division
11 / 4
11.0 / 4.0
11 / 4.0
15 / 3
16 / 3
has value 2
has value 2.75
has value 2.75
has value 5
has value 5
15
Arithmetic Operators
Modulus
the modulus operator % can only be used
with integer type operands and always
has an integer type result
its result is the integer type remainder of an
integer division
EXAMPLE
3%5=3 5%3=2 4%5=4 5%4=1
5%5=0 6%5=1 7%5=2 8%5=3
15 % 6 = 3 15 % 5 = 0
16