Professional Documents
Culture Documents
24 25 Concepts Programming
24 25 Concepts Programming
Example:
if - used only for true condition
Example:
for - number of iterations are known.(Entry controlled
loop/precondition loop)
Note:
Page 1 of 47
IGCSE U8-PROGRAMMING 23-24
Arr = [2,4,5,6,11]
2d array The Two-Dimensional array is organized as matrices which
can be represented as the collection of rows and columns
Example:
Arr=[[1,2,3],[4,5,6]]
Page 2 of 47
IGCSE U8-PROGRAMMING 23-24
Example : (Procedure)
def add():
a=int(input(“Enter a number:”))
b= int(input(“Enter a number:”))
sum=a+b
print(“Result:”,sum)
Example : (Function)
def add():
a=int(input(“Enter a number:”))
b= int(input(“Enter a number:”))
sum=a+b
return sum
Page 3 of 47
IGCSE U8-PROGRAMMING 23-24
While any data stored in RAM will be lost when the computer
is switched off, when data is saved to a file it is stored
permanently. Data stored in a file can thus be accessed by
the same program at a later date or accessed by another
program. Data stored in a file can also be sent to be used on
other computer.
Page 4 of 47
IGCSE U8-PROGRAMMING 23-24
Page 5 of 47
IGCSE U8-PROGRAMMING 23-24
PSEUDOCODE
Pseudo code is a simple method of showing an algorithm. It describes what the algorithm
does by using English key words that are very similar to those used in a high-level
programming language.
Declaration
of
Variables
Input and
output
statements
Page 6 of 47
IGCSE U8-PROGRAMMING 23-24
Conditional
statements
Iteration
statements
Page 7 of 47
IGCSE U8-PROGRAMMING 23-24
TOTALLING
COUNTING
Page 8 of 47
IGCSE U8-PROGRAMMING 23-24
ARRAYS
Note:
ONE-DIMENSIONAL ARRAY
TWO-DIMENSTIONAL ARRAY
Page 9 of 47
IGCSE U8-PROGRAMMING 23-24
PROCEDURES
Page 10 of 47
IGCSE U8-PROGRAMMING 23-24
FUNCTIONS
Page 11 of 47
IGCSE U8-PROGRAMMING 23-24
String Handling
Page 12 of 47
IGCSE U8-PROGRAMMING 23-24
FIE HANDLING
MyFile ← "MyText.txt"
INPUT TextLine
OUTPUT TextLine
Page 13 of 47
IGCSE U8-PROGRAMMING 23-24
EXAMPLES: Codes
Sequential programs: It is a set of logical steps executed in a sequence.(Without a
condition)
1. WAP to accept the radius of a circle. Calculate and display the area of a circle
Program
Output:
2. WAP to accept the Principal, time and rate of interest. Calculate and display the simple interest
Program
Output:
Page 14 of 47
IGCSE U8-PROGRAMMING 23-24
3. WAP to accept the First name and the Last name. Concatenate the First name and the Last name.
Display the full name
Program
Output:
SELECTION
4. WAP to accept a number. Check and display whether the number is positive (one condition)
Program
Output:
Page 15 of 47
IGCSE U8-PROGRAMMING 23-24
5. WAP to accept a number. Check and display whether the number is positive or negative (two
conditions)
Program
Output:
6. WAP to accept a number. Check and display whether the number is positive or negative or
zero(three conditions)
Program
Output:
Page 16 of 47
IGCSE U8-PROGRAMMING 23-24
7. WAP to accept a number and check whether the number is even or odd
Program
Output:
5%2 Ans=1
5/2 Ans=2.5
5//2 Ans=2
Page 17 of 47
IGCSE U8-PROGRAMMING 23-24
8. A cloth showroom has announced festival discounts and the gifts on the purchase of
items, based on the total cost as given below:
Up to ₹ 2,000 5%
Write a program to input the total cost. Compute and display the discount amount to be
paid by the customer.
Output:
Page 18 of 47
IGCSE U8-PROGRAMMING 23-24
9. WAP to create a very simple pizza-ordering menu. At this pizzeria, there’s only one
kind of pizza you can order: cheese pizza with 4 toppings. Your choices for toppings can
be one or more. Accept the cost of the pizza and calculate the total amount of the pizza
with the toppings. Refer price menu below for the toppings.
Toppings cost
Tomato ₹60
Capsicum ₹70
Mushroom ₹80
Sweetcorn ₹85
Program
Output:
Page 19 of 47
IGCSE U8-PROGRAMMING 23-24
10. MakeMyTour taxi charges from the passenger as per the tariff given below:
Distance Rate
Up to 5 km ₹ 100
Write a program to input the distance covered and calculate and display the amount
paid by the passenger.
Split 16
Add fare
Split 29
Add fare
Note:;
Slab 1 : 100
Slab2 : 10X10
Slab3 : 10 X 8
Slab4 : 25 * 5
Page 20 of 47
IGCSE U8-PROGRAMMING 23-24
Program
Output:
Page 21 of 47
IGCSE U8-PROGRAMMING 23-24
Output
Output
Page 22 of 47
IGCSE U8-PROGRAMMING 23-24
Output
Output
Page 23 of 47
IGCSE U8-PROGRAMMING 23-24
Output
Output
Page 24 of 47
IGCSE U8-PROGRAMMING 23-24
Output
Output
Page 25 of 47
IGCSE U8-PROGRAMMING 23-24
19. WAP to find product of all the numbers from 1 to 5.(Factorial of a number)
Program
Output
20. WAP to accept a number and print all the factors of the number
Program
Output
Page 26 of 47
IGCSE U8-PROGRAMMING 23-24
21. WAP to accept a number .Count and display the number of factors
Program
Output
22. WAP to accept a number and check whether the number is a prime number or not
Program
Output
Page 27 of 47
IGCSE U8-PROGRAMMING 23-24
WHILE LOOP
23. WAP to accept a number. SPLIT and display the digits in a new line.(for loop)
Program and output : (to split three digit number : for range is from (1,4)
Program and output : (to split four digit number : for range is from (1,5)
Program and output : (to split five digit number : for range is from (1,6)
NOTE:
In the above 3 programs, for loop modified according to the number of digits in an input. Loop runs
for 3 times for 3 digit number, 4 times for 4 digits number and 5 times for 5 digit number. Hence
the need of while loop.(number of iterations are unknown)
Page 28 of 47
IGCSE U8-PROGRAMMING 23-24
24. WAP to accept a number. SPLIT and display the digits in a new line.(WHILE loop)
Program and output : (to split three digit number :
Program and output : (to split four digit number : (SAME CODE)
Program and output : (to split five digit number : (SAME code)
NOTE:
While loop is not modified in any of the above programs but splits 3,4 or any number of digits.
Page 29 of 47
IGCSE U8-PROGRAMMING 23-24
25. WAP to accept a number .SPLIT and display the sum of all the digits.
26. WAP to accept a number .SPLIT and display the product of all the digits.
Page 30 of 47
IGCSE U8-PROGRAMMING 23-24
24. WAP to accept a number. SPLIT and display the sum of squares of all the digits.
Example : 123 12+22+32 =1+4+9 = 14
25. WAP to accept a number. SPLIT and display the sum of cubes of all the digits.
Example : 123 13+23+33 =1+8+27 = 36
26. WAP to accept a number. Check and display whether the number is Armstrong or not
Example : 153 13+53+33 =1+125+27 = 153
Variable “orig” is used to store the value of “num” as the value of “num” reaches to 0 inside the loop. So it
cannot be compared with “sum” as original number
Page 31 of 47
IGCSE U8-PROGRAMMING 23-24
27. WAP to accept a sequence of numbers and terminates the program when zero entered.
28. WAP to ask a question “who invented Java” and terminates the program when the user gives
the correct answer
Inventor: James Gosling
29. WAP to display the menu to order a pizza until the user enters a valid choice and terminates
when the valid choice is selected.
Page 32 of 47
IGCSE U8-PROGRAMMING 23-24
31. WAP to declare an array of size 5 and accept user input elements into an array
Page 33 of 47
IGCSE U8-PROGRAMMING 23-24
33. WAP to accept 5 elements. Find and display the count of even numbers and odd numbers
34. WAP to accept 5 elements. Find and display the sum of even numbers and odd numbers
Page 34 of 47
IGCSE U8-PROGRAMMING 23-24
35. WAP to accept 5 elements. Find and display the count and sum of all the prime numbers
Output:
Page 35 of 47
IGCSE U8-PROGRAMMING 23-24
36. WAP to accept 5 elements. Search an element in an array and display the message found or
not with an index of the search element
37. WAP to accept 5 names into an array. Search the name and display whether the name is
found or not
Page 36 of 47
IGCSE U8-PROGRAMMING 23-24
38. WAP to accept 5 elements. Find and display the maximum and minimum element in an array
Page 37 of 47
IGCSE U8-PROGRAMMING 23-24
38. WAP to accept 5 elements. Arrange the elements in an ascending order and display the result
Page 38 of 47
IGCSE U8-PROGRAMMING 23-24
38. WAP to accept 5 elements. Arrange the elements in an ascending order and display the result
Page 39 of 47
IGCSE U8-PROGRAMMING 23-24
A class consists of 5 students, and the class has to publish the result of all those students. You
need a table to store all those five students' names, subjects' names, and marks. For that, it
requires storing all information in a tabular form comprising rows and columns. A row
contains the name of subjects, and columns contain the name of the students. That class
consists of four subjects, namely English, Science, Mathematics, and Hindi, and the names of
the students are first, second, third, fourth, and fifth.
Page 40 of 47
IGCSE U8-PROGRAMMING 23-24
40. WAP to declare an array of size 2X3 and accept user input elements into an array and display them
41. WAP to declare an array of size 2X3 and accept user input elements into an array. Find and display
sum of all the elements in an array
Page 41 of 47
IGCSE U8-PROGRAMMING 23-24
42. WAP to declare an array of size 2X3 and accept user input elements into an array. Find and display
sum of all the elements in each ROW
43. WAP to declare an array of size 2X3 and accept user input elements into an array. Find and display
sum of all the elements in each COLUMN
Note: Write the column for loop then the row for loop to calculate the column sum
Page 42 of 47
IGCSE U8-PROGRAMMING 23-24
44. WAP to declare an array of size 2X3 and accept user input elements into an array. Count and
display the number of even numbers and odd numbers
45. WAP to declare an array of size 2X3 and accept user input elements into an array. display the sum
of even numbers and odd numbers
Page 43 of 47
IGCSE U8-PROGRAMMING 23-24
46. WAP to declare an array of size 2X3 and accept user input elements into an array. Count and
display the number of even numbers and odd numbers in each ROW
47. WAP to declare an array of size 2X3 and accept user input elements into an array. Count and
display the number of even numbers and odd numbers in each COLUMN
Page 44 of 47
IGCSE U8-PROGRAMMING 23-24
44. WAP to declare an array of size 2X3 and accept user input elements into an array. Find the
maximum and minimum element in an array
Page 45 of 47
IGCSE U8-PROGRAMMING 23-24
45. WAP to declare an array of size 4X2 and accept the first name and the last name in each for 4
people.
TASK 1 : Accept the first name and display the corresponding last name
TASK 2: Accept the last name and display the corresponding first name
Page 46 of 47
IGCSE U8-PROGRAMMING 23-24
OUTPUT:
Page 47 of 47