0% found this document useful (0 votes)
44 views

IPL Lab 1 Introduction

Here are C programs to solve the given problems: // Solve the equation: ax + b = 0 #include<stdio.h> int main() { int a, b, x; printf("Enter coefficients a and b: "); scanf("%d %d", &a, &b); x = -b/a; printf("Solution is x = %d", x); return 0; } // Conversion from USD to VND #include<stdio.h> int main() { float usd, rate, vnd; rate = 23000; printf("Enter USD: "); scanf("%f", &usd); v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

IPL Lab 1 Introduction

Here are C programs to solve the given problems: // Solve the equation: ax + b = 0 #include<stdio.h> int main() { int a, b, x; printf("Enter coefficients a and b: "); scanf("%d %d", &a, &b); x = -b/a; printf("Solution is x = %d", x); return 0; } // Conversion from USD to VND #include<stdio.h> int main() { float usd, rate, vnd; rate = 23000; printf("Enter USD: "); scanf("%f", &usd); v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

SAIGON UNIVERSITY

FACULTY OF ELECTRONICS AND TELECOMMUNICATIONS

PROGRAMMING TECHNOLOGY

1 - Lab experiment

• Lecturer: Thien Le
Instructions to a computer
• When a computer is started, it automatically does some
processes and comes to a particular screen.
• How does this happen?
==>
• The operating system software exists inside the computer.
• The operating system is referred to as system software.
• The operating system is made up of a set of programs.
• Every program tries to give solution to one or more problems.
• Each program is set of instruction to solve the problem it tries
to address.
A group of instructions make up a program and a group of
programs make up software.
2
Instructions to a computer
• Example:
– Make a lemon juice:
• Cut the lemon
• Put the lemon, sugar, water, ice
• Blend and serve
• Let us analyze these instructions:
– Take the first instruction: Is it complete? Does it answer
the question as to ‘Where’ the lemon has to be taken?
– Take the second instruction; again here it is not very
clear as to how much sugar should be put?

3
Instructions to a computer
• The computer also processes the data based on the
set of instructions given to it. Needless to say, the set
of Instructions given to the computer also should be
meaningful and complete:
– Sequential
– Finite
– Accurate
• Each of the instruction in the instruction set is known
as a Command and the set itself is known as a
Program.

4
The Programming approach to solving problems
Example:
Assume that you want to make a quick visit from your classroom to the
cafeteria, which is located in the basement. Having understood the task,
we would need to work out the steps involved, before actually
performing this task. The steps would look as shown below:

The procedure given above lists well defined and clear set of executable
steps that need to be performed in order to solve the problem at hand.
Such a set of steps is called an algorithm.
Algorithms are written using two standard methods-pseudo
codes, and flowcharts.
5
Software, Program and Commands

6
Versions of C

Evolved over the years:


• 1972 – C invented
• 1978 – The C Programming Language published; first
specification of language
• 1989 – C89 standard (known as ANSI C or Standard C)
• 1990 – ANSI C adopted by ISO, known as C90
• 1999 – C99 standard
• mostly backward-compatible
• not completely implemented in many compilers
• 2007 – work on new C standard C1X announced
In this course: ANSI/ISO C (C89/C90)
7
What is C

Widely used today


• extends to newer system architectures
• efficiency/performance
• low-level access

8
Features of C

C features:
• Few keywords
• Structures, unions – compound data types
• Pointers – memory, arrays
• External standard library – I/O, other facilities
• Compiles to native code
• Macro preprocessor

9
What is C used for?

Systems programming:
• OSes, like Linux
• microcontrollers: automobiles and airplanes
• embedded processors: phones, portable
electronics, etc.
• DSP processors: digital audio and TV systems

10
Editing C code

• .c extension
• Editable directly

11
The C Program Structure

Some rules for programs written in C are as follows:


• All keywords are lower cased
• C is case sensitive, do while is different from DO
WHILE
• Keywords cannot be used for any other purpose, that
is, they cannot be used as a variable or function name
• main() is always the first function called when a
program execution begins (discussed later in the
session)

12
The C Program Structure

C program:
main ()
{
/* This is a sample program */
int i = 0;
i = i + 1;
.
.
}

13
The C Compiling and Running a program

14
Editing C code

• .c extension
• Editable directly

15
The Programming approach to solving problems
Input-Process-Output Cycle:

16
Example 1: Define the Input, Process, Output of these tasks.
• Calculate the basic salary of employees in Jan, 2021 according
to the equation: salary of a employee = number of working
days * basic salary of a working day
– Input: basic salary of one working day, number of working days
– Process: multiply two input values
– Output: salary of employee

17
The Programming approach to solving problems
Pseudo code:
‘pseudo code’ is not actual code (pseudo=false). Pseudo
code uses a certain standard set of words, which makes
it resemble a code. However, unlike code, pseudo code
cannot be compiled or run.
Example:

18
The Programming approach to solving problems
Flowcharts:
A flowchart is a graphical representation of an algorithm.
It charts the flow of instructions or activities in a
process. Each such activity is shown using symbols.
Example:

19
The Programming approach to solving problems
Flowcharts symbols

20
The Programming approach to solving problems
Flowcharts:
Example 2: accepted two numbers from the user, added them up,
(stored the result in a third variable) and displayed the result.

21
The Programming approach to solving problems
Flowcharts: notes
• Initially concentrate only on the logic of the problem and draw
out the main path of the flowchart.
• A flowchart must have only one START and one STOP point.
• It is not necessary to represent each and every step of a
program in the flowchart. Only the essential and meaningful
steps need to be represented.

22
Flowcharts: The IF construct
• Example 3: Let us consider the customer is given a discount if
he makes a purchase of above $100. Every time a customer is
billed, a part of the code has to check if the bill amount
exceeds $100. If it does then deduct 10% of the total amount,
otherwise, deduct nothing.
• Pseudo code :
IF customer purchases items worth more
than $100
Give 10% discount
• The IF construct:

23
Flowcharts: The IF construct
• Example 4: accepts a number from the user, performs the MOD
operation on it, and checks if the remainder is zero. If it is, then
it displays a message, otherwise it just exits.

• Pseudo code :

24
Flowcharts: The IF
construct
• Example 5: accepts a
number from the user,
performs the MOD
operation on it, and
checks if the remainder
is zero. If it is, then it
displays a message,
otherwise it just exits.

• Flowchart

25
Flowcharts: The IF-ELSE construct
• Example:

26
Flowcharts: The IF-ELSE construct
• Example:

27
Flowcharts: The Loops construct
• Example 6: write a program that would display a name 1000
times.

28
Exercise 1: Define the Input, Process, Output of these tasks.
• Solve the equation: ax + b = 0
• Find the biggest number of two numbers
• Coversion from USD to VND and vice versa

29
Exercises 2: Write a pseudo code and draw flowchart
• Calculate the basic salary of employees in Jan, 2021 according
to the equation: salary of a employee = number of working
days * basic salary of a working day
• Solve the equation: ax + b = 0
• Find the biggest number of two numbers
• Coversion from USD to VND and vice versa
• Coversion degrees Celsius to Fahrenheit and vice versa [C/5 =
(F-32)/9]
• Calculate the average grade of a student marks including
Physics, Chemistry, and Biology.
• Sove the equation ax2 + bx + c = 0
• Check whether two input numbers have the same value or not

30
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b, c;
printf("Calculate sum of two numbers \n");
printf("Enter a number: ");
scanf("%d", &a);
printf("Enter a second number: ");
scanf("%d", &b);
c = a + b;
printf("The sum is: %d . \n", c);
getchar();
}
31
Exercises
Using the sample C programme, modify to solve these
problems:
• Solve the equation: ax + b = 0
• Coversion from USD to VND and vice versa
• Coversion degrees Celsius to Fahrenheit and vice versa [C/5 =
(F-32)/9]
• Calculate the average grade of a student marks including
Physics, Chemistry, and Biology.
• Calculate the basic salary of employees in Jan, 2021 according
to the equation: salary of a employee = number of working
days * basic salary of a working day

32

You might also like