CSC 103 Chap 6
CSC 103 Chap 6
CSC 103 Chap 6
Chapter - 6
Programming Concept
Lecture – (week – 5)
Pseudocode:
Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying LFT
with 30
Print length in cm (LCM)
Algorithm: START
Input
1. Start Lft
2. Input Lft Lcm Lft x 30
3. Lcm Lft x 30
4. Print Lcm Print
Lcm
5. Stop
STOP
Pseudocode:
Input two values value1 & value2
if is value1 is greater than value2
Print “The largest value is value1”
else
Print “The largest value is value1”
17 September 2019 CSC 103 33
Different Examples of Flowchart
Example 2: START
Determines the largest value.
Input
VALUE1,VALUE2
Algorithm:
1. Start Y is N
VALUE1>VALUE2
2. Input VALUE1,VALUE2
3. if (VALUE1 > VALUE2) then
4. MAX VALUE1 MAX VALUE1 MAX VALUE2
5. else
6. MAX VALUE2
Print
7. endif “The largest value is”,
8. Print “The largest value is”, MAX MAX
9. Stop STOP
Pseudocode:
Input a set of 4 marks
Calculate their average by summing and dividing by 4
if average is below 50
Print “FAIL”
else
Print “PASS”
17 September 2019 CSC 103 35
Different Examples of Flowchart
Example 3:
Determines Pass or Fail
Algorithm:
1. Start
2. Input M1,M2,M3,M4
3. GRADE (M1+M2+M3+M4)/4
4. if (GRADE <50) then
Print “FAIL”
else
Print “PASS”
5. Stop
Programming Language: C
Example:
#include <stdio.h>
void main()
{
printf("Hello World");
}
Variables are named memory locations that have a type, such as integer
or character, which is inherited from their type. The type determines
the values that a variable may contain and the operations that may
be used with its values.
17 September 2019 CSC 103 42
Variable Declaration
To Declare one variable:
type variable_name;
Example: int id;
To Declare more than one variables:
type variable_list;
Example: char gender, section;
type must be a valid C data type.
variable_list may consist of one or more identifier names separated by
commas.
Examples:
char gender , section;
int id;
float cgpa;
17 September 2019
id = 112233; CSC 103 43
Rules for writing variable name in C:
The name of a variable can be composed of letters, digits, and the
underscore character.
Rules for writing variable name in C are-
In order to use a variable within a program, the compiler needs to know in advance
the type of data that will be stored in it.
For this reason, we declare the variables at the start of the program.
Variable declaration consists of giving a new name and a data type for the variable.
This is normally done at the very start of the program.
17 September
9/17/2019
2019 CSC 103 50