Computer 10th Fbise Solved Notes by Encore Star College & Academy 03064941878
Computer 10th Fbise Solved Notes by Encore Star College & Academy 03064941878
ii. What is algorithm and what is the role of algorithm in problem solving?
Ans: Algorithm means method, procedure, technique or plan. Algorithm is a step by step problem solving method that
is easy to understand and follow. It is a set of steps that clearly defines a sequence of operations to solve a problem.
v. Draw any four graphical symbols used in flowchart and explain them.
a. Flow Line:
It is a line with arrow head used to connect various flowcharts symbols and indicates the flow of
Control in the flowchart.
b. Start/Stop Symbol:
It is rounded rectangular shaped symbol .It is used to indicate the start or end of a flowchart. We
can write the words Start or Stop inside this symbol. A flowchart only can have one start but it may have many
ends.
d. Process Symbol:
A rectangular block is used for any data processing operation. All the calculations appear inside
the processing symbol, such as “SUM=A+B”. Variables are also initialized inside the process
symbol, such as “K=1”.
e. Decision Symbol:
A diamond shaped symbol represents decision in a flowchart and it contains a condition. If the
condition is true, the path marked YES is to be followed. If the condition is false, the path marked
NO is to be followed. The words TRUE or FALSE can also be used instead of YES or NO.
f. Connector Symbols:
These symbols are used to connect one part of a flowchart to the other
on the same page( On-Page connector) or on the new page (Off-Page connector)
Ans: there are five steps are involved in problem solving on the computer.
Q4. Write an algorithm to calculate the area of a rectangle for given breadth and length.
Ans: Step 1: Start
Input the Breadth (B) and Length (L) of a rectangle
Step 2: Calculate the area (A) by multiplying L with B
Step 3: Print A
Step 4: Stop
Q5. Write an algorithm that inputs length in inches and calculate and print it in centimeters.
Ans: Step 1: Start
Input the Length in inches (LI)
Step 2: Calculate the length in cm (LCM) by multiplying LI with 2.54
Step 3: Print LCM
Step 4: Stop
Q6. Write an algorithm that inputs marks and prints the message “PASS” or “FAIL”. Passing marks are 33.
Ans: Step 1: Start
Input Marks (M)
Step 2: Check if (M<33) then Print “FAIL” otherwise GOTO Step 3
Step 3: ELSE Print “PASS”
PRODUCT = 1 x 3 x 5 x 7 x 9 x 11 x 13 x 15
Step 1: Start
Initialize variable K to 1 and Prod =1
K= 1 Prod= 1
Step 2: Increment K by 2
K=K+2
Step 3: Find the product
Product= Prod x K
Step 4: Check if the value of K is less than 16
IF K<16 THEN GOTO Step 2 otherwise GOTO Step 5
Step 5: Print Product
Step 6: Stop
Step 1: Start
Enter the Number N whose table is to be generated
Step 2: Initialize the value of I with 10
i. Convert flowchart of an algorithm to calculate the area of a rectangle for given breadth and length.
START
INPUT L, B
AREA=L * B
PRINT AREA
STOP
START
LCM=LI * 2.54
PRINT LCM
STOP
iii. Convert flowchart of an algorithm that inputs marks and prints the message “PASS” or “FAIL”. Passing
marks are 33.
START
YES
IF M<33
NO
PASS FAIL
STOP
START
SUM =SUM+K
K=K+5
YES NO
IF K<60
PRINT SUM
STOP
v. Convert flowchart of an algorithm to find the product of given numbers.
PRODUCT = 1 x 3 x 5 x 7 x 9 x 11 x 13 x 15
START
K =1, PROD=1
K =K+2
PROD=PROD *K
NO YES
IF K<16
PRINT SUM
STOP
START
ENTER A NUMBER N
I=10
PROD=N * I
PRINT N, I, PROD
I=I-1
YES NO
IF PROD>0
STOP
Short Questions
Q2. Give short answers to the following questions.
i. Define computer program.
A computer program is a set of instructions (statement) written in a programming language to solve a particular
problem and achieving specific results. Any task performed by a computer is controlled by a set of instructions that are
executed by the microprocessor. A large variety of programming languages have been developed for writing computer
programs to use the computer as a problem-solving tool. Each statement of a programming language has syntax and
semantic.
Variable: is a symbolic name that represents a value that can change during execution of a program.
Variable are of two types.
1. Numeric Variables: are used to represent numeric values in computer programs. They represent integer
and floating-point values. Examples are sum, avg, length, salary, marks etc.
2. Character variables: represent character values in computer programs. It represent single character or a
string of characters. Examples are name, city, gender etc.
vii. Which of the following are valid C variables? Give the reason if not a valid variable.
Area, 5x, Sum, net pay, float, _ age, else, case, size 22, my_weight
Ans: Valid C variables: my-weight, area, size22, Sum
Not Valid C Variables Reason
5x A variable can’t be start with number.
net pay Space can’t be used in variable name.
float Data types can’t be used as variable name.
_age Special character (_) can’t be used in variable name.
else Commands cannot be used as variable name.
case Commands cannot be used as variable name.
viii. What are reserved words? Why they should not be used as variable names?
Reserved Words: The words that are part of programming language and have special purposes in computer programs
are called reserved words or keywords. Reserved words are always written in lowercase.
Why they should not be used as variable names?
Because they have predefined use and cannot be used for any other purpose or even as a variable. There are 32 words
defined as reserved words in C. examples are int, do, while, void, if, break etc
a) C / C++
C:
• Developed in early 1970s by Dennis Ritchie at Bell Lab.
• Become one of the most popular programming languages today.
• Highly structure, easy to understand and use.
• In the past, used for writing system programs such as OS, compilers, assemblers etc.
• Today, used for writing all types of application programs such as Office, educational & games software’s
.
C++:
• Developed by Bjarne Stroustrup at Bell Lab during 1983-1985.
• C++ is a superset of C, meaning that any valid C program is also a valid C++ program.
• The purpose was to provide programming facilities to easily and quickly write more powerful programs.
b) Visual Basic
• VB is a high level language which is evolved from the earlier version called BASIC.
• BASIC stands Beginner’s All- purpose Symbolic Instruction Code.
• VB is a very popular programming language for writing Windows and Web applications with graphical environment.
• VB is commonly used for developing business programs such as payroll system & inventory control program.
• The user can also write programs related with engineering, science, arts, education, games etc.
c) C#
• C# (pronounced as C-sharp) is a language developed in 2000 by Microsoft Corporation.
• It is simple, modern, general-purpose programming language.
• Syntax of C# is very similar to C and C++ and it also have some features of Java.
• Easy and efficient.
• It provides facilities to write Web applications that can be used across the internet.
• All types of programs including games, utilities, operating systems etc can be developed in C#.
d) Java
• Java is a high level language developed by Sun Microsystems.
• It is very similar in syntax to C and C++.
• In Java, the user can write all types of programs as those written in other programming languages and small
programs that can be embedded in a Web page accessed through Internet.
• Java is ideal language for network computing.
• It is used for writing programs for a wide range of devices, computers and networks.
• It is widely used in Web applications.
• The current versions of most of the Web browsers are made Java enabled like Microsoft internet explorer, Firefox
and Mozilla.
Q4. Differentiate between compiler and interpreter.
Compiler Interpreter
1 A compiler converts a program into machine code A interpreter converts a program into machine code as
as a whole at a time. line by line or as a single statement at a time.
2 Compiler creates object code file. Interpreter does not create object code file.
3 Program execution is fast. Program execution is slow.
4 Error detection and removal is difficult. Error detection and removal is simple and easy.
5 Memory requirement is more Memory requirement is less
6 Example: C, PASCAL, JAVA Example: BASIC, Java Script, Perl, VB
Q6. What are the rules for specifying a variable name in C language?
• A variable begins with a letter or underscore (_) and may consist of letters, underscores and/or digits.
• The underscore may be used to improve readability of the variable name. Example over_time.
• There is no restriction on the length of a variable name.
• Both upper and lower case letters are allowed in naming variables. An upper case letter considered different from a
lower case letter. Example the variable AVG is different from Avg or avg.
• Special characters cannot be used as variable name. e.g #, ?, @ etc.
• Reserved words of C language such as int, case, if, etc. cannot be used as variable names.
• There must be no embedded blank in the name of variable. Example m ass is not correct.
3 Example: compiler converts the sum of two Example: the programmer converts the division of
float numbers to an int. two int numbers to float.
#include <stdio.h> #include <stdio.h>
void main (void) void main (void)
{ {
float value1=2.5; int value1=2.5;
float value2=5.3; int value2=5.3;
Int result; float result;
result=value1+value2; result=(float)value1+value2;
printf(“Result:%d”, result); printf(“Result:%f”, result);
} }
• Most of new programming languages use IDE to create, compile and run programs.
• IDE is comp software that brings all the processes & tools required for program development into one place.
• IDE’s aim is to make the life of programmers easier.
• Today’s modern IDEs have user-friendly Graphical User Interface (GUI).
• Text Editor: A text editor is a simple word-processor that is used to create and edit source code of a program. Files
created by a text editor are plain text files. Most of the editors automatically highlight compile errors to simplify
removing them.
• Compiler: A compiler is a software that translates C language program (source program) into machine code (object
program that can be understood and executed by the computer. It also detects syntax errors and gives hints to
programmer to correct them.
• Linker: Linker is a software that translates object program into a single executable program. During this process, if
it could not find the definition of a particular function that is used in the program, then it would assume that is
defined in C library. It will replace this function in the object program with the code from C library and then create a
single executable program.
• Loader: It is a software that loads programs into memory and then executes them.
• Debugger: It is a software that executes a program line by line, examines the values stored in variables and helps
in finding and removing errors in programs.
%d decimal integer
%i integer
%Id long decimal integer
%f floating-point (decimal notation)
%e floating-point (exponential notation)
%c single character
%s string
ii. Why escape sequence is used? Explain with examples.
The special characters used in C language to control printing on the output device called escape sequences.
These characters are not printed. These are used inside the control strings. An escape sequence is a combination
of a backslash (\) and a code character. The backslash (\) is called the control character. A list of commonly used
escape sequences.
\a Produces alert (bell) sound
\b Moves cursor background by one position
\n Moves cursor to the beginning of next line
\r Moves cursor to the beginning of the current line
\t Moves cursor to the next horizontal tabular position
\\ Produces a backslash
\’ Produces a single quote
\’’ Produces a double quote
\? Produces a question mark
The program given below demonstrates the use of escape sequence.
#include<stdio.h>
#include<conio.h>
void main(void)
{
printf(“\nRings bell three times.\a\a\a”);
printf(“\nRemoves 2 spaces between the name. sohail \b\bHeader”);
printf(“\n\nLeaves a blank line before printing this line.”);
Printf(“\n \rMoves this text to beginning of line..”);
printf(“\nIssues tab after each word. I\tam\tSohail”);
printf(“\nDisplays backslash symbol. \\”);
printf(“\nDisplays name is single quotes. \’Sohail\’ ”);
printf(“\nDisplays name is double quotes. \’Sohail\” ”);
printf(“\nDisplays question mark at the end. Who are you\?”);
getch();
}
Example
#include<stdio.h>
#include<conio.h>
Void main(void)
{
int a, b, c;
printf(“Enter the first number:”);
scanf(“%d”, &a);
printf(“Enter the second number:”);
scanf(“%d”, &b);
c=a+b;
printf(“The sum is %d”, c);
getch();
}
Q3. Describe how basic and compound assignment operators are used?
Basic Assignment Operators: The basic assignment operator is = This is used to assign value of an expression to
a variable. It has the general form:
variable=expression
Where expression may be a constant, another variable to which a value has previously been assigned or a
formula to be evaluated. For example
sum=a+b;
Compound Assignment Operators: In addition to = there are a number of assignment operators unique to C.
These include +=,-=,*=, /= and %=. Suppose op represents an arithmetic to assign value of an expression to a
variable.
Variable op=expression
Examples
sum=sum + n;
sum +=n;
Q4. Describe the functions of the following operators?
i. Relational Operators
Relational Operators are used to compare two values of the same type. These are used in expressions
when a decision is to be based on a condition. After evaluation of a relational expression, the result
produced is either True or False. Relational operators are used in programming for decision making.
Types of Relational Operators
Six types of relational operators are available in C language.
Operator Definition
== equal to
!= not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to
The following are some examples of relational operators. c>=a+b , x<5.3 , n= =20 , count!=10
b) Logical OR (||) Operator Just like the logical AND operator, one relational expression is to the
left and the other to the right of the OR operator. The compound condition is true if either of the
conditions is true or both conditions are true. It is considered false only if both of the conditions
are false.
Syntax: Expression1 || Expression2
Truth table for OR operator (+)
Expression-1 Expression-2 Expression-1 && Expression -2
True True True
True False True
False True True
False False False
Example: (n<10) || (n>25)
c) Logical NOT (!) Operator The logical NOT operator is used with a single expression
(condition) and evaluates to true if the expression is false and evaluates to false if the expression is
true/ in other words, it reverses the result of a single expression.
Syntax: !Expression1
Truth table of NOT operator: (-)
Expression !Expression
True False
False True
Example: !(a<b)
iii. Conditional Operators
A conditional (Ternary) operator is a decision-making operator. It has the following form.
condition? expression1 : expression2;
When this statement is executed, the condition is evaluated. If it is true, the entire conditional expression
takes on the value of expression1. If it is false, the conditional expression takes on the value of
expression2. The entire conditional expression takes on a value and can therefore be used in an assignment
statement.
Example
a= (k>15)? x*y : x+y;
# include <stdio.h>
#include <conio.h>
void main(void)
{
int num1, num2, num3, sum, prod, avg;
printf(“Enter the three numbers separated by ‘,’\n”);
scanf(“%d, %d, %d”, &num1, &num2, &num3);
sum= num1 + num2 + num3;
prod= num1* num2 * num3;
avg= sum/3;
printf(“the sum of the three numbers is: %d\n”, sum);
printf(“the prod of the three numbers is: %d\n”, prod);
printf(“the avg of the three numbers is: %d\n”, avg);
getch();
}
Q6. Write a program that reads the length and width of a rectangle and prints its area.
# include <stdio.h>
#include <conio.h>
void main(void)
{
float length, width, area;
printf(“Enter length of rectangle:”);
scanf(“%f”, &length);
printf(“Enter width of rectangle:”);
scanf(“%f”, &width);
area= length* width;
printf(“Area of rectangle= %f sq. units”, area);
getch();
}
Q7. Write a program that reads the length of one side of a cube and prints its volume.
# include <stdio.h>
#include<conio.h>
void main(void)
{
float side, volume;
printf(“Enter length of any side of cube\n”);
scanf(“%f”, &side);
volume= side*side*side;
printf(“Volume of Cube : %0.4f\n”, volume);
getch();
}
# include <stdio.h>
#include<conio.h>
void main(void)
{
float fahren, celsius;
printf(“Enter the temperature in celsius\n”);
scanf(“%f”, &celsius);
fahren= (9.0/5.0) * celsius + 32;
printf(“ %.2fC is equal to %.2fF\n”, celsius, fahren);
getch();
}
Q9. Write a program that reads name and address of a person and prints it on the screen using gets( ) and
puts( ) functions.
# include<stdio.h>
#include<string.h>
void main(void)
{
char name[50], add[50];
printf(“Enter your name:”);
gets(name);
printf(“Enter your address:”);
gets(add);
printf(“Your name is:”);
puts(name);
printf(“Your address is:”);
puts(add);
getch();
}
Q3. What is control structure? Explain conditional control structure with examples.
Control Structure:
In a programming language, a control statement is an instruction which determines the sequence of
execution of other statements in a program. Control structures are used in programs to implement
decisions.
Conditional control structure:
A conditional statement is an instruction in a programming language that contains a condition. When a
conditional statement is executed, first the condition is evaluated and then based on the result (true or
false), a particular statement or a set of statements is executed.
Conditional statements of C language are if, if-else, else-if and switch statements.
Structure of If Statement: Structure of If–else Statement:
General form: General form:
if (condition) if (condition)
{ {
Block of statements Block of statements
} }
else
{
Block of statements
}
• The switch statement is similar to the else-if statement. It is used when multiple choices are
given and one choice is to be selected.
• When switch statement is executed, the expression is evaluated. Based on the result of
expression one of the cases in the switch statement is executed. The result of expression is
compared with the constant values given after the keywords case. If the result matches the
constant value after any case then the statements under that case are executed.
• In switch statement, it is allowed to use a variable within the parenthesis instead of an
expression based on which statements under a case can be executed.
• The purpose of break statement is to exit the body of the switch statement after executing the
statements under a case and transfer control to the first statement following the end of the
switch statement.
• If no case is matched then the statements under the default keyword are executed. Its use is
optional. If it is not used then the controls exits from the body of the switch statement and goes
to the first statement following the end of the switch statement.
• The expression should be of type int, char but not float.
Ans: I am a student
I am a student
I am a student
I am a student
I am a student
GOOD BYE
Ans:
30
25
20
15
10
v. Find errors in the following code.
int k, a
a=3;
k=1;
while(k<10);
{
Printf(“\n%f\t%f”, k, k*a-1);
K=k+2;
}
Ans:
int a, k;
a=3;
k=1;
while(k<10)
{
printf(“\n%d\t%d”, k, k*a-1);
k=k+2;
}
Output:
1 2
3 8
5 14
7 20
9 26
vi. Convert the following for loop into a while loop.
Int k; Ans: Int k;
for(k=25; k>0; k=k-3); k=25;
Printf(“\n%d”, k); while(k>0);
{
Printf(“\n%d”, k);
K=k-3;
}
printf(“\n”);
n=65;
while(n<=90);
{ OUTPUT
Printf(“%c”, n);
ABCDEFGHIJKLMNOPQRSTUVWXYZ
n=n+1;
}
getch();
}
The do while statement is used to implement loop structure when it is required to execute the loop at least one.
The Syntax or general form of do while() loop
do
{
body of loop
}
While (test condition);
Example: Program prints all the lower-case letters on a single line using do while loop. The ASCII code for lower-
case letters are in the range 97 to 122.
#include<stdio.h>
#include<conio.h>
Void main(void)
{
int n;
printf(“\n”);
n=97;
do
{ OUTPUT
Printf(“%c”, n);
n=n+1; abcdefghijklmnopqrstuvwxyz
}
while(n<=122);
getch();
}
Q5. Explain the purpose of break and continue statements with one example each.
The Break statement:
C language provides the break statement to exit from a loop as soon as certain condition occurs. It is used in for,
while and do while statements. Break statement is also used to exit the body of switch statement after
executing the statements under a case and transfers control to the first statement following the end of the
switch statement.
Example: Program to check for prime number by using break statement.
#include<stdio.h>
#include<conio.h>
void main(void)
{
int num, k, a=0;
printf(“\nEnter a number:”);
scanf(“%d”, &num);
for(k=2; k<=num/2; k++)
{
OUTPUT
a=1;
Enter a number: 23
break;
23 is a prime number
}
If(a==0)
printf(“\n%d is a prime number.”, num);
else
printf(“\n%d is not a prime number.”, num);
getch();
}
Example-1: Program by using nested loop to print the products of numbers as given below.
1x1=1 Output
Program
1x2=2 1x1=1
#include<stdio.h>
1x3=3 1x2=2
1x4=4 #include<conio.h>
1x3=3
2x1=2 void main(void) 1x4=4
2x2=4 { 2x1=2
2x3=6 int j, k, prod; 2x2=4
2x4=8 for(j=1; j<=3; j++); 2x3=6
3x1=3 for(k=1; k<=4; k++); 2x4=8
3x2=6 { 3x1=3
3x3=9 3x2=6
Prod=j*k;
3x4=12 3x3=9
printf(“\n%2d x %2d = %2d”, j, k, prod);
3x4=12
getch();
}
1x2=2
Example-2: Program by using nested loop to calculate the sum of the integers for each integer
1x1=1 from 1 to n,
where n is the value that the user of the program enters. 1x2=2
1x3=3
#include<stdio.h> 1x4=4
#include<conio.h>
void main(void) OUTPUT 1x1=1
{ 1x2=2
int j, k, sum, n; Enter the upper limit (n): 8 1x3=3
1x4=4
printf(“\nEnter the upper limit (n) :”);
Integer Sum 2x1=2
scanf(“%d”, &n);
2x2=4
printf(“\n\tInteger\t\tSum”); 1 1 2x3=6
for(j=1; j<=n; j++) 2 3 2x4=8
{ 3 6 3x1=3
Sum=0; 4 10 3x2=6
for(k=1; k<=j; k++) 5 15 3x3=9
sum=sum+k; 6 21 3x4=12
7 28
printf(“\n\t%3d\t\t %3d, j, sum);
8 36
}
getch();
}
𝑿 𝑿 X X
̅𝒀
𝑿 ̅𝒁
̅ ̅𝒀
𝑿 ̅𝒁 ̅
𝑿𝒀𝒁 ̅ 𝒀𝒁
𝑿 ̅
𝑿
̅𝒁
𝑿𝒀 ̅ ̅𝒁
𝑿𝒀 XYZ ̅
𝑿𝒀𝒁
X
𝒁 Z Z 𝒁
Q3. Draw the graphical symbols of AND, OR, NOT, NAND and NOR gates and write their functions.
There are three basic logic gates used in digital circuit s which are AND, OR and NOT gates.
AND GATE
▪ The AND gate has two or more inputs that can be LOW (0) or HIGH (1).
▪ The output is HIGH only when all the inputs are HIGH.
▪ It produces a LOW output when at least one of the inputs is LOW.
The logic operation of a two-input AND gate is shown below with all the possible input combinations
and the resulting output for each.
OR GATE
▪ The OR gate has two or more inputs.
▪ The output of an OR gate is LOW only when all the inputs are LOW.
▪ It produces a HIGH output when at least one or more of its inputs are HIGH.
The logic operation of a two-input OR gate is shown below with all the possible input combinations
and the resulting output for each.
NOT GATE
▪ The NOT gate performs the functions of inversion.
▪ Therefore, it is also known as inverter. It has a single input.
▪ The output of a NOT gate is HIGH when the input is LOW and vice versa.
The logic operation of a NOT gate is shown below with LOW and HIGH inputs.
NOR GATE
▪ The NOR gate combines the OR and NOT gates.
▪ Such that the output will be 0 when any input is 1 as shown in Fig.
▪ Its logic expression is F=x + y which indicates that inputs x and y are first ORed and then the result is
inverted.
▪ Inversion is indicated by a bar.
▪ A NOR gate always gives an output that is the inverse(opposite) of an OR gate.
Symbol, expression and truth table of NOR gate is shown given below
Q4. Explain how NAND and NOR gates can be created using AND, OR and NOT gates.
i. The NAND gate can be easily created by using an AND gate and a NOT gate as shown in Fig.
ii. The NOR gate can be easily created in a similar way by using an OR gate and a NOT gate as shown in Fig.
Example: http:\\www.aiou.edu.pk/NewStudents.asp
Web Hosting:
• Web hosting is a service that uploads a website on a Web server and makes it available for computer users.
• It makes the website running on a computer all the time that is connected to Internet.
• To host a website a Web server and a permanent connection to the Internet is required.
• It also requires website administration such as managing and configuring a Web server and virus protection.
• Computer users’ first design Web pages on their computer and test it to ensure they work properly.
• When Web pages are ready they are uploaded on a Web server to make them available for others.
• There are companies that provide Web hosting service.
• These companies provide 24 hour support and online control for managing the website.
Q6. Describe how background color and image are applied to Web page.
Applying Background and Foreground colors
To apply a background color in a page, insert the bgcolor attribute and for foreground color, insert text attribute in the
<body> tag.