Download presentation
Presentation is loading. Please wait.
1
CC213 Programming Applications
Week #1
2
Software Development Method
Specify problem requirements Analyze the problem Design the algorithm to solve the problem Implement the algorithm Test and verify the completed program Maintain and update the program
3
Steps Defined Problem - Specifying the problem requirements forces you to understand the problem more clearly. Analysis - Analyzing the problem involves identifying the problem’s inputs, outputs, and additional requirements. 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. Implementation - Implementing is writing the algorithm as a program. Testing - Testing requires verifying that the program actually works as desired. Maintenance - Maintaining involves finding previously undetected errors and keep it up-to-date.
4
Converting Miles to Kilometers
Problem: Your boss wants you to convert a list of miles to kilometers. Since you like programming, so you decide to write a program to do the job. Analysis We need to get miles as input We need to output kilometers We know 1 mile = kilometers Design Get distance in miles Convert to kilometers Display kilometers
5
4. Implementation
6
C Program structure Function Header Function Body
7
Identifiers Declarations
An identifier must consist only of letters, digits, and underscores. An identifier cannot begin with a digit. A C reserved word cannot be used as an identifier. A standard identifier should not be redefined. C compilers are case sensitive. (Rate, rate and RATE are viewed as different identifiers) Valid identifiers: letter1, inches, KM_PER_MILE Invalid identifiers: 1letter, Happy*trout,return
8
Giving a Value to a Variable
9
Output Function SYNTAX Examples :
printf( format string , print list ) ; Printf(format string); Place holder printf(“That equals %f kilometers. \n”, kms); printf(“enter the distance in miles> ”); printf( “Hello, World?\n“); Escape sequence
10
Output Function
11
Input Function SYNTAX Examples : scanf( format string , input list ) ;
Place holder scanf(“%lf”, &miles); Ampersand
12
Input Function
13
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.
14
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); }
15
Arithmetic Operators Division
the result of the division operator depends on the type of its operands if one or both operands has a floating point type, the result is a floating point type. Otherwise, the result is an integer type Examples / has value / has value / has value 15 / has value 5 16 / has value 5
16
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.