Review Yourself
1. State whether the following statements are true or false.
a. The QBASIC statements are first stored in the memory of the computer
and executed only when the command RUN is given.
b. The QBASIC keyword LET is optional in the syntax; the equal sign is
sufficient.
c. The LET statement is used to recieve input from the keyboard during
program execution.
d. BASIC divides the line into print zones of 24 spaces.
e. The LOCATE statement is commonly used with PRINT statements.
2. Fill in the blanks.
a. The ___________ statement is used to clear the screen and leaves the
cursor at the top left corner of the screen.
b. The __________ is used for storing a value in a variable.
c. The ___________ statement is used to receive input from the keyboard
during program execution.
d. The purpose of __________ statement is to store the numeric and string
constants that are accessed by the program’s READ statement(s).
e. _________________ function causes program output to shift to the right
a specified number of spaces.
3. Answer the following questions.
a. What is the use of REM statement in a program?
b. What is the difference between LET statement and INPUT statement?
c. What are the various options that can be used with PRINT statement to
display multiple values on a single line?
d. Write the function and syntax of the following statements:
i. LET
ii. INPUT
iii. PRINT
iv. READ...DATA
v. LOCATE
e. What is the main difference between TAB statement and LOCATE statement?
JBD
Computer Studies-8 201
4. Write an assignment statement for each of the following situations.
a. Assign a value 60 to the variable x.
b. Increase the value of the variable ctr by 100.
c. Double the value assigned to the value count.
d. Assign the string “First Program” to the variable class.
e. Assign the value represented by the expression a^2 + b^2 to the variable c.
f. Add 34 to c and store it in a variable d.
g. Store the value 34 in variable d.
h. Subtract 8 from b and store it in a variable d.
5. What will the following programs print on the screen?
a. freeze = 32 : boil = 212
freeze = 0 : boil = 100
PRINT freeze, boil
END
b. x = 0
y=2
x=y*4
PRINT x; y
END
c. a = 0
x = 23
a = x MOD 2
PRINT x, a
END
d. READ s, c
DATA 850,800
profit = s - c
percent = (profit / c) * 100
PRINT “Actual profit =”; profit
PRINT “Profit =”; percent; “%”
END
JBD
202 Computer Studies-8
6. Write a program:
a. To input side of a cube. Print the volume and the total surface area.
Hint: V = l3 and TSA = 6l2
b. To accept the base and height of a triangle and calculate the area of the
triangle.
Hint:
A=1/2*b*h
c. To find the area of circle.
( Hint : Area of Circle = PI*R^2 )
d. To find the area of parallelogram.
( Hint : Area of Parallelogram = B*H )
e. To find the square, cube and square root of a given number.
Hands-On Practice Time
a. Write a program to input the length and breadth of a rectangle and calculate
the perimeter of a rectangle.
b. Write a program to input the length, breadth and height of a box and calculate
the volume of a box.
c. Write a program to find the cost of painting the four walls of a room.
d. Write a program that assign values to the selling price and cost price of an
article. Calculate the actual profit.
e. Write a program with READ and DATA statements to find the simple interest
and the amount for the following:
Principal - Rs.2500
Time - 4 years
Rate - 2%
f. Ramesh bought a computer set costing Rs.24000 and sold it for Rs.25000.
Find his profit percent.
g. Rajesh Shrestha sales hard disks and pen drives. He gets 2% commission on
the hard disk and 3% on the pen drives. Write a program to input the sale
amount of hard disk and pen drives. Calculate and print the total commission
he should get.
JBD
Computer Studies-8 203
Chapter 18
Control
Statements
Objectives
After completing this chapter, you will be able to:
y Differentiate between sequential and program control statements.
y Identify and describe the two different categories of branching and looping
statements.
y Define looping statement.
y State the use and function of control statements.
C Ooncept verview
The program flow in high-level languages is sequential i.e., they appear in order
from top to bottom. The statement in which these statements are sequentially
executed are called sequential control structure programs. These types of
programs are easy to understand and modify. But not many programs execute all
their statements in strict order from top to bottom. Most of the programs decide
what to do in response to changing circumstances. These programs change the
order of execution of statements or repeat a group of statements until certain
specified conditions are met. These types of programs are useful for storage of
data, manipulation of data and modification of data. QBASIC provides facilities
for controlling the order of execution of statements. They are known as the
program control statements.
The control statements of QBASIC can be put into the following categories:
• Branching statements
• Looping statements
JBD
204 Computer Studies-8
Branching statement
Branching statement allows your program to transfer the control to some other
specified statement instead of the sequential execution. There are two types of
branching statements: unconditional and conditional branching statements.
Unconditional branching
Unconditional branching statement allows one to make an absolute jump to
another point in the program. It allows an unconditional transfer of control.
Therefore, the sequence of execution is broken without performing a test and
control is transferred to the target statement having the statement label. The most
commonly used unconditional branching statement is GOTO statement.
GOTO statement
GOTO statement allows an unconditional transfer of control from one part of the
program to the other without performing a test. The general format of GOTO
statement is:
GOTO [line number | line label]
Where,
line number is the valid line from 0 to 65,529.
line label is the valid line label starting with a letter.
Example
CLS
first:
REM “To find the area of a rectangle”
INPUT “Enter length of a rectangle”; l
INPUT “Enter width of a rectangle”; w
Area = l * w
PRINT “Area of the rectangle is:::”; Area
GOTO first
END
JBD
Computer Studies-8 205
Conditional branching
Conditional statement is a statement that allows selective execution of statements
based on a condition having a certain value. It enables the computer to decide
which of the several possible actions are to be taken. On the basis of a given
condition a selected segment of the program is executed. It depends upon the
state of a particular condition being true or false. The most commonly used
conditional statement is IF...THEN statement. Conditional branching statement
is also called decision-making statement. The most commonly used conditional
branching statements are:
• IF...THEN statement
• SELECT CASE statement
IF...THEN statement
IF...THEN statement allows branching depending upon the value of an
expression. The statement to be executed or ignored depends upon the condition.
The different forms of IF...THEN statement are:
• IF...THEN...ELSE statement
• IF...ELSEIF...ENDIF statement
IF...THEN statement
IF...THEN statement tests a particular condition; if the condition evaluates to true,
a course-of-action is followed i.e., a statement or set-of-statements is executed.
Otherwise (if the condition evaluates to false), the course-of-action is ignored.
The general format of the IF...THEN statement is:
IF <condition> THEN <statement>
IF...THEN...ELSE Statement
IF...THEN...ELSE is an extension of IF...THEN statement. If the condition specified
after IF is true, then the statement after THEN statement will be executed. And if
it is false, the statement given next to ELSE will be executed. The general format
of the IF...THEN... ELSE statement is:
IF <condition> THEN <statement1> ELSE <statement2>
Example
INPUT “Enter annual income”; i
IF i > 50000 THEN t = .3*i ELSE t = .2*i
PRINT “Tax=”; t
END
JBD
206 Computer Studies-8
IF...ELSEIF...ENDIF statement
IF...ELSEIF...END IF statement is another variation of the IF...THEN...ELSE
statement. You can have any number of ELSEIF clauses. The conditions are
evaluated from top to bottom. As soon as one of the conditions controlling the
IF is true, the statement associated with that IF is executed, and the rest of the
ladder is bypassed. If none of the conditions is true, then the final ELSE statement
will be executed. The final ELSE acts as a default condition; that is, if all other
conditional tests fail, then the last ELSE statement is performed. The general
format of IF...ELSEIF... ENDIF statement is:
IF [condition1] THEN
[statementblock-1]
ELSEIF [condition2] THEN
[statementblock-2]
....
ELSE
[statementblock-n]
END IF
Example
CLS
INPUT “Enter any number”;num
IF num>0 THEN
PRINT “Positive Number”
ELSEIF num<0 THEN
PRINT “Negative Number”
ELSE
PRINT “Zero”
END
SELECT CASE statement
SELECT CASE statement is a multi-branch selection statement. This selection
statement successively tests the value of an expression against a list of integer or
character constants. When a match is found, the statements associated with that
constant are executed. If the value does not match, the CASE goes on to the next
CASE statement. The general format of SELECT CASE statement is:
SELECT CASE test exp
CASE test 1
JBD
Computer Studies-8 207
statements
CASE test 2
statements
....
CASE ELSE
statements
END SELECT
Where,
test exp is the expression that is evaluated to decide which branch of the SELECT
CASE statement is executed.
test1, test2 are the possible results of the test expression.
statements are QBASIC executable statements that are executed when the test
exp evaluates true for test1 or test2.
Example
INPUT “Enter a character”; a$
SELECT CASE a$
CASE “A”
PRINT “Uppercase letter A”
CASE “a”
PRINT “Lowercase letter a”
END SELECT
Looping Statement
The looping statements allow a set of instructions to be performed repeatedly
until a certain condition is fulfilled.
The repetition continues while the condition set for it remains true. When the
condition becomes false, the loop ends and the control is passed to the statement,
following the loop. The looping statements allow the programmer to control the
number of times a specific instruction is to be repeated. The looping statements
are also called iteration statements. QBASIC supports the following looping
statements:
FOR...NEXT
WHILE...WEND
DO...LOOP
JBD
208 Computer Studies-8
FOR...NEXT statement
FOR...NEXT statement is used to execute a series of instructions a given number
of times. The general format of FOR...NEXT statement is:
FOR variable = x to y <STEP z>
<statements to be executed>
NEXT variable
Where,
variable is a numeric variable that controls the number of repetitions to be
performed.
x is a numeric expression that is the starting value of the counter.
y is a numeric expression that is the final value of the counter.
z is the number that is used to increase or decrease the counter.
Example
A=3
FOR J = 1 TO 5
PRINT A
A = A / 10
NEXT
END
WHILE...WEND statement
WHILE...WEND statement is an entry-controlled loop. It allows a block of
statements to be executed repeatedly till the condition is true. The WHILE...
WEND statement has the following syntax:
WHILE <condition>
<program statements>
WEND
The condition can be numeric or logical expression or a variable that WHILE
evaluates. The loop iterates while the condition evaluates to true. When the
condition becomes false, the program control passes to the line after the loop-
body code.
In a WHILE...WEND loop, a loop control variable should be initialized before
the loop begins as an uninitialized variable can be used in a condition. The loop
should be updated inside the body of the WHILE...WEND loop.
JBD
Computer Studies-8 209
DO...LOOP statement
DO...LOOP statement causes a set of program statements to execute repeatedly
until certain conditions are met or as long as certain conditions are true. The
different variation of DO...LOOP statements are:
a. DO WHILE <condition>
<statement>
LOOP
• Tests the <condition> first and if true, executes the <statement>.
• Loops based on condition.
Example
c=1
DO WHILE c <= 10
PRINT c
c=c+1
LOOP
END
b. DO
<statement>
LOOP WHILE <condition>
• Executes the <statement> first and then tests the <condition>.
• Loops at least once, then
tests the <condition>.
c. DO UNTIL <condition>
<statement>.
LOOP
• Tests the <condition> first and if false, executes the <statement>
• Loops till the <condition> is
false.
d. DO
<statement>
LOOP UNTIL <condition>
• Executes the <statement> and then tests the <condition>.
• Loops at least once, then
tests the <condition>.
JBD
210 Computer Studies-8
Nested Looping
A loop structure placed inside another loop structure is said to be a nested loop.
When a loop is defined inside another loop, the inner loop operates as many
times for all the values of the outer loop. The rules for the formation of nested
loop are:
• An outer loop and inner loop cannot have the same control variable.
• The inner loop must be completely nested inside the body of the outer
loop.
• The inner loop must terminate before the outer loop.
• Outer loop opens first but closes last.
• Loops must never cross each other.
Example
FOR x = 1 TO 5
FOR y = 1 TO x
PRINT y;
NEXT
PRINT
NEXT
END
String Functions
A string is a collection of alphanumeric characters specified within double quotes.
String is also known as an alphanumeric constant. String functions operate upon
strings and manipulate them. These are called string manipulators, since they
manipulate or rearrange the values within a string.
ASC function
ASC function returns the ASCII code corresponding to the character of a string.
ASCII is an acronym for American Standard Code for Information Interchange.
ASCII code is a numeric value between-128 and 127 that is used to represent a
character internally in the computer. ASC function takes a string as argument.
The syntax is as follows:
ASC (string)
Where,
string may be any string expression.
JBD
Computer Studies-8 211
CHR$ function
CHR$ function returns a character that corresponds to a specific ASCII values. It
takes a number between -128 and 127 as argument. The general format of CHR$
function is:
CHR$ (n)
Where,
n is a value from 0 to 255.
Example
FOR I = 1 TO 255
PRINT I “=” CHR$ (i) ;
NEXT I
END
RIGHT$ function
RIGHT$ function extracts and returns a specific number of characters from the
right of a string. The general format is:
RIGHT$ (string expression, n)
Where,
string expression is a string constant, string variable or string expression.
n is an integer expression in the range 0 - 32767 that specifies the number of
characters to be extracted from the right-hand side of the string. If n equals zero,
the null string (length zero) is returned.
Example
A$ = “NEPAL”
FOR I = 1 TO 5
PRINT RIGHT$(A$, I)
NEXT I
END
Program Output
L
AL
PAL
EPAL
NEPAL
JBD
212 Computer Studies-8
MID$ function
MID$ function extracts and returns a specific number of characters from within a
string. The general format is:
Syntax 1
MID$ (string expression, start, length)
Where,
string expression is the string from which the sub-string has to be extracted.
start is the starting position to extract from the string expression.
length is the number of characters to extract.
Syntax 2
MID$ (string variable, start, length) = string expression
Where,
string variable is the string whose characters will be replaced.
start is the starting position for replacement in the target string.
length is an optional parameter that specifies the number of characters to be
replaced. If not specified, the entire string expression is used.
string expression is the replacement string.
Example
INPUT “Enter the string:”; A$
C=1
FOR I = 1 TO LEN(A$)
IF MID$(A$, I, 1) = “ “ THEN C = C + 1
NEXT I
PRINT “No. of words in the string=”; C
END
LEFT$ function
LEFT$ function extracts and returns a specific number of characters from the left
of a string. The general format is:
LEFT$ (string expression, n)
Where,
string expression is a string constant, string variable or string expression.
n is an integer expression in the range 0 - 32767 that specifies the number of
characters to be extracted from left-hand side of the string. If n equals zero, the
null string (length zero) is returned.
JBD
Computer Studies-8 213
Recap
• The program flow in high-level languages is sequential i.e., they appear in
order from top to bottom.
• QBASIC provides facilities for controlling the order of execution of statements.
They are known as the program control statements.
The control statements of QBASIC can be put into the following categories:
• Branching statements
• Looping statements
• Branching statement allows your program to transfer the control to some
other specified statement instead of the sequential execution.
• The unconditional branching statement allows one to make an absolute jump
to another point in the program.
• GOTO statement allows an unconditional transfer of control from one part of
the program to the other without performing a test.
• Conditional statement is a statement that allows selective execution of
statements based on a condition having a certain value.
• IF...THEN statement tests a particular condition; if the condition evaluates
to true, a course-of-action is followed i.e., a statement or set-of-statements is
executed.
• SELECT CASE statement is a multi-branch selection statement. This selection
statement successively tests the value of an expression against a list of integer
or character constants.
• The looping statements allow a set of instructions to be performed repeatedly
until a certain condition is fulfilled.
• FOR...NEXT statement is used to execute a series of instructions a given
number of times.
• WHILE...WEND statement is an entry-controlled loop. It allows a block of
statements to be executed repeatedly till the condition is true.
• DO...LOOP statement causes a set of program statements to execute repeatedly
until certain conditions are met or as long as certain conditions are true.
• LEFT$ function extracts and returns a specific number of characters from the
left of a string.
JBD
214 Computer Studies-8
Review Yourself
1. State whether the following statements are true or false.
a. The statement in which the statements are sequentially executed are
called control flow programs.
b. IF...THEN statement allows an unconditional transfer of control from
one part of the program to the other.
c. The looping statements allow a set of instructions to be performed repeatedly
until a certain condition is fulfilled without performing a test.
d. FOR...NEXT statement is an entry-controlled loop.
e. DO...LOOP statement causes a set of program statements to execute
repeatedly until certain conditions are met.
2. Fill in the blanks.
a. The _____________statement allows an unconditional transfer of control
from one part of the program to the other without performing a test.
b. The ______________ statement allows branching depending upon the
value of an expression.
c. The ____________ statement is used to execute a series of instructions a
given number of times.
d. ___________ function returns a character that corresponds to a specific
ASCII values.
e. ____________ function extracts and returns a specific number of
characters from within a string.
f. ___________ function counts and returns the total number of characters
in a string.
3. Answer the following questions.
a. What is a control flow statement?
b. What do you mean by branching statement?
c. Differentiate between conditional and unconditional branching
statements.
d. What is looping statement?
e. What do you understand by nested loop?
f. What is the purpose and syntax of the following statements:
i. IF...THEN ii. FOR...NEXT
JBD
Computer Studies-8 215
4. Write equivalent SELECT CASE statement for the following.
IF code=”a” THEN
PRINT “Summer Season”
ELSEIF code=”r” THEN
PRINT “Rainy Season”
ELSEIF code=”w” THEN
PRINT “Winter Season”
ELSE
PRINT “Wrong Code”
ENDIF
5. What will the following programs print on the screen?
a. FOR outloop = 1 TO 5
PRINT inloop;
NEXT
END
b. A = 1
B=1
L=1
C=0
PRINT A, B,
DO
PRINT A
C=A+B
A=B
B=C
L=L+1
LOOP WHILE L <= 10
END
c. N = 5
C=1
WHILE C <= 10
PRINT N; “*”; C; “=”; N * C
C = C + 1
WEND
END
JBD
216 Computer Studies-8
6. Write the following program segment using the following looping statements.
a. (Use While...Wend)
A=3
FOR J = 1 TO 5
PRINT A
A = A / 10
NEXT
END
b. (Use Do...Loop)
N=3
FOR I=0 TO 5
LET A=A+N*10^I
PRINT A
NEXT
END
c. (Use For...Next)
c=0
INPUT “Enter positive number”; n
WHILE n <> 0
n = n \ 10
c=c+1
WEND
PRINT “The number of digits ::”; c
END
d. (Use While...Wend)
INPUT “Enter the number”; n
DO
d = n MOD 10
r = r * 10 + d
n = n \ 10
LOOP WHILE n <> 0
PRINT r
END IF
JBD
Computer Studies-8 217
7. Write a program that will ask the user to input age and print whether he/she
is eligible to vote or not.
8. Write a program that will allow user to enter three numbers and print the
largest of these numbers.
9. Write a program that will print even numbers from 1 to 50 in reverse order.
10. Write a program to generate odd integers between 1 and 100.
11. Write a program to print the sum of first ten natural numbers.
12. Write a program to input a number and reverse it.
13. Write a program to input a number and find the sum of its individual digits.
14. Write a program to input any ten numbers from the user and count the
number of odd and even numbers.
15. Write a program to count the number of vowels in an input string.
16. Write a program to input a string and then print it in the reverse order. For
example, if the input string is “NEPAL”, it should print LAPEN.
17. Write a program to input a string and count the number of words in it.
18. Write a program to input a string and count the number of consonants in it.
Hands-On Practice Time
1. Write a program to input name of a candidate and marks in three subjects.
Calculate total and percentage. Print all the informations with division using
the following conditions:
If percentage is greater than or equal to 70, grade is A.
If percentage is greater than or equal to 60 and less than 70, grade is B.
If percentage is greater than or equal to 50 and less than 60, grade is C.
Otherwise grade is D.
2. Write a program to input total amount deposited in a fixed deposit account
and total number of years. The program should calculate interest according
to the following rates.
Duration Rate
1 year 14%
2 years 14.5%
3 years 15%
JBD
218 Computer Studies-8
3. Write a program to:
a. Input any ten numbers from the user and count the number of odd and even
numbers.
b. To count the number of vowels in an input string.
c. To input a string and then print it in the reverse order. For example, if the
input string is “NEPAL”, it should print LAPEN.
d. To input a string and count the number of words in it.
e. To input a string and count the number of consonants in it.
4. Write a program to input the length and breadth of a rectangle and calculate
the perimeter of a rectangle.
5. Write a program to input the length, breadth and height of a box and calculate
the volume of a box.
6. Write a program to find the cost of painting the four walls of a room.
7. Write a program that assign values to the selling price and cost price of an
article. Calculate the actual profit.
8. Write a program to print the following series:
i. 1,4,9,16,25
ii. 5, 10, 15, 20, 25
iii. 1, 3, 6, 10, 15
iv. 1, 8, 27, 125
v. 2, 22, 222, 2222, 22222
9. Write a program to print the following patterns on the screen.
a. 1 b. 1 2 3 4 5
1 2 1234
1 2 3 123
1 2 3 4 12
1 2 3 4 5 1
c. 5 d. 1
5 5 121
5 5 5 12321
5 5 5 5 1234321
5 5 5 5 5 123454321
JBD
Computer Studies-8 219
10. Write a program to print the following patterns on the screen.
a. N b. P R O G R A M
N E P R O G R A
N E P P R O G R
N E P A P R O G
N E P A L P R O
P R
P
c. N E P A L d. N
E P A L E
P A L P
A L A
L L
e. G
OGR
ROGRA
PROGRAM
f. P R O G R A M
R O G R A
OGR
G
JBD
220 Computer Studies-8
Test Paper F.M: 75
Time: 2:30 mins
Group A (Fundamentals) (1 x 5 = 5)
1. State whether the following statements are true or false.
a. In 1979, the US Defence Department named a programming language
ADA in her honour.
b. The examples of fourth generation computers are IBM system/360,
National Cash Register Century Series, ICL 1900 series, DATA GENERAL
range and IBM 370 series.
c. Hybrid computer is a digital computer that accepts analog signals,
converts them to digital and processes them in digital form.
d. Wordprocessing software allows to communicate to any location in the
world using either fax or electronic mail.
e. A bus network comprises a continuous length of cable that connects the
device usually a hub or a switch.
2. Fill in the blanks. (1 x 5 = 5)
a. ______________, a German mathematician and philosopher, invented a
digital mechanical calculator called Stepped Reckoner in 1694.
b. The first integrated circuit was developed in 1958 by ________________
of Texas Instruments and Robert Noyce of Fairchild Semiconductor.
c. ______________________
is a computer that operates on data by measuring changes in continuous
physical variables such as voltage, resistance and rotation.
d. _________________ is the software designed to meet the specific
requirements of an organization or individual.
e. A_____________________consists of computers connected to a central
network connector, which is usually a hub or a switch.
3. Match the following. (1 x 5 = 5)
Program virus A program designed to detect and remove
viruses from computer system.
Norton AntiVirus A computer virus designed to infect the boot
sector of the disk.
JBD
Computer Studies-8 221
Antivirus A computer virus designed to infect executable
Boot sector virus program files having an extension .exe, .com, or
Kaspersky .dll.
An antivirus program developed by Kaspersky
Lab designed to protect users from malware and
is primarily designed for computers running
Microsoft Windows and Mac OS X.
AntiVirus developed and distributed by
Symantec Corporation.
4. Give the full form of the following abbreviations. (1 x 5 = 5)
a. UNIVAC-1 b. IBM c. EDSAC
d. KB e. BIT
5. Answer the following questions. (2 x 5 = 10)
a. What is a system software? Give an example of system software.
b. What is a computer network? What are the advantages of computer
network?
c. What is a program virus? Give any two examples of program viruses.
d. What is the role of multimedia projector in information and communication
technology?
e. What are the main objectives of Cyber law of Nepal 2061 BS (2004)?
6. Convert the following DECIMAL numbers to equivalent BINARY numbers. (1 x 4 = 4)
a. 12510 b. 79210 c. 64310 d. 47510
7. Convert the following BINARY numbers to equivalent DECIMAL numbers: (1 x 4 = 4)
a. 101012 b. 1100012 c. 1001002 d. 1100102
8. Solve the following binary arithmetic. (1 x 2=2) b. 11111 - 11011
a. 110110 + 100101
Group B (Practical)
9. Answer the following questions. (2 x 5 = 10)
a. What is a command? Distinguish between internal command and external
command.
JBD
222 Computer Studies-8
b. What is mail merge? Write the steps to use mail merge.
c. What is a function? What are the three elements of function?
d. What is the difference between the Dodge tool?
e. What are HTML tags and where are they used?
10. Write down the appropriate DOS command(s) to perform the following task. (1 x 5 = 5)
a. Display the current date and allows you to enter new date.
b. Copy the file jay.txt from drive C: to drive B:
c. Delete a group of file ending with an extension ext from drive C:.
d. Format a disk in drive A: and copies the system files on to it.
e. Performs a quick format of a disk in drive A:
11. Write the output of the following HTML coding. (1 x 3 = 3)
<HTML>
<BODY>
Being <B>friendless</B> taught me how to be a friend. <BR>
(a+b)<SUP>2</SUP>=a<SUP>2</SUP> +2ab+b<SUP>2</SUP> <BR>
H<SUB>2</SUB>SO<SUB>4</SUB>
</BODY>
</HTML>
12. Write an algorithm and draw a flowchart for the following problems. (1 x 2 = 2)
a. To print cubes of first 10 natural numbers.
b. To input an integer and find whether it is an even or an odd.
13. Write a program to: (3 x 5 = 15)
a. Input any ten numbers from the user and count the number of odd and
even numbers.
b. To count the number of vowels in an input string.
c. To input a string and then print it in the reverse order. For example, if the
input string is “NEPAL”, it should print LAPEN.
d. To input a string and count the number of words in it.
e. To input a string and count the number of consonants in it.
JBD
Computer Studies-8 223
Practical Paper
F.M: 25
Time: 1 hr
1. Perform the following tasks in your computer and request the examiner
to check the output of every problem:
a. Design a web page according to the following specifications:
b. Insert any suitable picture at the center below the heading.
c. Specify an alternate text that can be displayed in place of the
image.
d. Change the background colour to yellow.
Text Content
GOLDEN KEY TO HAPPINESS
The greatest powers of life are thought, speech and prayer. The key to
successful living is the intelligent and sincere application of prayer.
Prayer is a desire for right action to take place in your life and in the
lives of others. It is a request for perfect circumstance.
2. Write a program to input two values and find their sum, difference,
product and quotient.
3. In a company salary is fixed according to the qualification of the person
as below:
Qualification Basic Pay HRA as % of Basic Pay
SLC 1000 10%
Graduate 2000 12%
Post Graduate 3500 15%
Doctorate 5000 18%
Write a program which will read the basic pay and qualification (1-
SLC, 2-Graduate, 3-Post Graduate, 4-Doctorate) and should print the
total salary.
4. Write a program to find the sum of the series:
1 + 1/2 + 1/3 + 1/4 + ... 1/n
JBD
224 Computer Studies-8