Vous êtes sur la page 1sur 158

Computer FundamentalsIntroduction to Programming

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Introduction to
Programming
Languages and
Programming
1. Explain with examples the concept of (i) Encapsulation (ii) Inheritance (iii) Operator
Overloading (iv)Function overloading and (v) friend function in object oriented
programming. 10 October-2014
2. Explain with examples the concepts of encapsulation, inheritance, operator
overloading, function overloading and friend function that are used in an object
oriented programming language. April-2014
3. Explain with examples the syntax errors, runtime errors, and logical errors that you
can encounter when writing computer programs. What are the steps that are
followed to debug these problems of a program? 10 April-2014
4. You have an array A of 100 elements. Write a program using any high level language
of your choice, which finds and displays the odd numbers of the array. April-2014
5. Name three programming languages. Using the appropriate computer program,
explain the steps involved from writing a computer program to its execution. 10
April-2003
6. Name three popular high level programming languages. Write a small program in
any of the languages to compute the sum of two real numbers and display the result
on the monitor. 10 April-2004
7. What is flow chart? Device a flow chart that finds out the highest mark obtained in
an examination. Assume that only one student obtained the highest mark. 7 April2005
8. Write a program using C, C++ or FORTRAN which reads two integer numbers from
a keyboard and prints their sum to the computer console. 8 April-2005
9. What do you understand by the term Programming Language? Classify
programming languages and explain each of them with examples. Distinguish
between a compiler and an interpreter. 10 April-2007
10. Describe, with examples, the difference between low level and high-level
programming languages used in computers. What do you understand by the term
Object Oriented Programming? 10 October-2007
11. What is a flow chart? Five numbers denoted by the variables A, B, C, D and E are
supplied as input. Draw a flow chart for the logic to print these numbers in
descending order of magnitude. 2+8 April-2008
12. A set of examination papers, which have been graded with scores from 0 to 100 is to
be searched to find how many of them are above 90. Prepare of flowchart to do this
job.
10 April-2008

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 1 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

13. Distinguish between machine language, assembly language and high level language.
Mention the types of errors that can be occur in a computer program. 6+4 April-2008
14. What is a compiler? What types of errors can be detected by a compiler? Mention the
advantages of high level languages over machine languages. 3+3+4 October-2008
15. What is a debugger? How does it help a programmer? 5 October-2008
16. What are program comments? Why are they needed? 5 October-2008
17. What is an algorithm and what is a flowchart? Three numbers denoted by the
variables A, B and C are supplied as input data. Draw a flow chart for the logic to pick
and print the largest of the three numbers. 4+6 October-2008
18. Draw a flowchart to add up all the even numbers between 0 and 100. In the same job,
the results of the calculation are to be printed before ending. 10 October-2008
19. What is a compiler? What is the difference between a compiler and an interpreter?
What types of errors are detected by a compiler?
2+4+4 April-2009
20. Write the advantages and limitations of machine language and assembly language.10
April-2009
21. What is a compiler? What is the difference between a compiler and an interpreter?
What types of errors are detected by a compiler?
2+4+4 October-2009
22. Draw a flowchart to add up all the even numbers between 0 100. Before ending,
print the result of the calculation. 10 October-2009
23. Give a flow chart for the following problem. Read data values and keep on adding
them until negative value is entered. Output the sum and the number of data values
read and added. 10 April-2010
24. Write a program for the problem in 4(a) using any programming language.
10
April-2010
25. What is a compiler? What types of errors are detected by a compiler? 6 April-2010
26. Draw a flow chart for the summing up first N positive integers. 10 October-2010
27. Write a program for the problem in 4(a) using any programming language.
10
October-2010
28. What is a high level language? What features are necessary in a high level language?
5 October-2010
29. Discuss the differences between a procedural programming language and an object
oriented programming language. 10 October-2010
30. What is an algorithm? What is a flowchart? 4 April-2011
31. Draw a flowchart of the logical steps needed to print the name and age of the oldest
and youngest student in a class. The input contains the name and age of the students.
8 April-2011
32. Write a program in a high-level language for the problem in question no 6(b).
8
April-2011
33. What is an Interpreter? How does it differ from a compiler? 5 April-2011
34. What types of errors can be detected by a compiler? What type of errors cannot be
detected? 5 April-2011
35. What are the advantages and limitations of a machine language? 5 April-2011
36. Explain the differences between a source program and an object program. 5 April2011
37. What is a compiler? What types of errors can be detected by a compiler? 5 October2011
38. What are the advantages and limitations of an assembly language? 5 October-2011

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 2 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

39. Explain the difference between a source program and an object program. 5 October2011
40. Write the advantages of a high level programming language. 5 October-2011
41. Give a flow chart to find the largest value of given numbers.10 October-2011
42. Write a program for the problem in 5(a) using any programming language.
10
October-2011
43. What is an Interpreter? How does it differ from a compiler? 5 April-2012
44. What are the advantages and limitations of a machine language?
5 April-2012
45. What types of errors can be detected by a compiler? What types of errors cannot be
detected by a compiler? 5 April-2012
46. Describe any two basic services provided by Internet. 5 April-2012
47. What is an algorithm? What is a flowchart? 4 April-2012
48. Give a flow chart for the following problem. Read data values and keep on adding
them until negative value is entered. Output the sum and the number of values read
and added. 8 April-2012
49. Write a program for the problem in 48 using any programming language. 8 April2012
50. Write a program to find the maximum of three given numbers taken as input. 8
October-2012
51. Given an integer, write a program to find the summation of all digits of the given
integer number. 8 October-2012
52. Write a program to swap the values of two variables. 4 October-2012
53. What do you mean by the machine code of a CPU? 5 October-2012
54. What are the differences between a high level programming language and a low-level
programming language? 3 October-2012
55. What do you mean by pseudo-code of a program? 2 October-2012
56. Write a loop that will run indefinitely. 2 April-2013
57. Write a program to find summation, average, maximum and minimum of numbers.
8 April-2013
58. What are the usages of continue and break statements in a programming language?
4 April-2013
59. Write a program that takes an year as an input, and gives yes as output if the given
year is a leap year and No as output if the year is not a leap year. 5 April-2013
60. Write a function to find the length of a given string. 3 April-2013
61. What are the differences between a structured programming language and an object
oriented programming language? 4 April-2013
62. Write a program, using any high-level language, which reads three numbers from the
keyboard, and outputs the minimum and maximum values. Also write the output of
the following program segment. 8 October-2013
int i, j, k;
k=2;
j = 10;
i = 5;
while( ) {
printf(i=%d, j=%d and k=%d, i, j, k);
j=j-2;

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 3 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

}
63. Explain the three properties of an object oriented programming language. What are
the steps that are followed to debug a program? 6 October-2013
64. Compare while and for loops that are used in a programming language. List the
names an symbols of the logical and relational operators that are used in C/C++. 6
October-2013
65. Write a program, using any high-level language, which asks the user to enter the
radius of a sphere, and then computes and displays the spheres area and volume
4
where = 4 2 and = 3 . 8 October-2013
3
66. Write a program to find the maximum, minimum and summation of 50 numbers. 10
October-2014
67. Draw a flowchart of the logical steps needed to print the name and age of the oldest
student in a class. 10 April-2009

Course Name: Computer Fundamentals


Course Co-Ordinator: Engr. Syed Mir Talha Zobaed
B.Sc. in Computer Science and Engineering (First Class First)
M.Sc. Engineering (Pursuing),
University of Rajshahi
Research: Brain Computer Interfacing
Contact:
Email: s.m.talha.jubaed@gmail.com
telecoaching.royalengg.academy@gmail.com
Website: www.royalengineeringacademy.page.tl
Hotline: +88-01911-088706
+88-01712-535813
+88-01719-033364

Royal Engineering Academy, Rajshahi


[An Ultimate Destination to be an Engineer through AMIE Examination]

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 4 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Basics of This Chapter


OOP is a powerful way to approach the job of programming. Programming methodologies have
changed dramatically since the invention of the computer, primarily to accommodate the increasing
complexity of programs.
Object-oriented programming took the best ideas of structured programming and combined them
with several new concepts. The result was a different way of organizing a program. In the most
general sense, a program can be organized in one of two ways: around its code (what is happening)
or around its data (who is being affected). Using only structured programming techniques,
programs are typically organized around code. This approach can be thought of as "code acting on
data." For example, a program written in a structured language such as C is defined by its functions,
any of which may operate on any type of data used by the program.
Object-oriented programs work the other way around. They are organized around data, with the key
principle being "data controlling access to code." In an object-oriented language, you define the data
and the routines that are permitted to act on that data. Thus, a data type defines precisely what sort
of operations can be applied to that data.
To support the principles of object-oriented programming, all OOP languages have three traits in
common: encapsulation, polymorphism, and inheritance.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 5 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What do you understand by the term Programming Language? Classify programming
languages and explain each of them with examples. Distinguish between a compiler and an
interpreter. 10 April-2007
Programming Language:
A programming language is a notation for writing programs, which are specifications of a
computation or algorithm.
A programming language is a formal constructed language designed to communicate
instructions to a machine, particularly a computer. Programming languages can be used to create
programs to control the behavior of a machine or to express algorithms.
A computer or a system is operated by given a set of rules and instruction to perform some
task. These sat of rules and instructions are able to control the working of computer or any automated
and/or manipulated machine. To control the computer system using these sequential set of grammatical
rules are known as programming language. In other words, A programming language is a vocabulary and
a set of grammatical rules for instructing a computer system to perform any specific task. Hence we can
say that a programming language plays a very important role to control and operating a computer system.
The description of a programming language is usually split into the two components of
syntax (form) and semantics (meaning). Some languages are defined by a specification document (for
example, the C programming language is specified by an ISO Standard), while other languages (such as
Perl) have a dominant implementation that is treated as a reference. Some languages have both, with
the basic language defined by a standard and extensions taken from the dominant implementation being
common.
Following are some of the examples of Programming Languages:
1. Java
2. C
3. C#
4. C++
5. Objective-C
6. PHP
7. Visual Basic
8. Python
9. Perl
10. JavaScript
Classification of Programming Languages:
All the computer programming languages are broadly classified into the following;

Machine level Language


Assembly level Language
High-level Language

Machine level languages (First Generation of programming language):


Its the lowest level and named as first generation of programming language. Machine level language
consist only two condition i.e. either true (1) or false (0); this type of language known as binary
language. A computer system could understand only binary language i.e. all the instruction feed into the
computer system must be in the form of 0 or 1. Machine level languages are very tough to understand
by the humans.
Advantages of machine level language:

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 6 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


There have many advantage of machine level language; some of them are listed below;

Machine level languages are directly interacting with computer system.


There is no requirement of software of conversion like compiler or interpreters.
It takes very less time to execute a program, because there is no conversion take place.

Disadvantages of machine language:


Some of the disadvantages of machine level language are listed below;

Its machine dependent language i.e. individual program required for each machine.
To develop a program in machine language, its too hard to understand and program.
Its time consuming to develop new programs.
Debugging process is very hard because of finding errors process is typical.
Machine language is not portable language.

Assembly level languages (Second Generation programming language):


Its a middle level and named as second generation programming language. It contains the same
instruction as machine level language, but the instructions and the variables have specific name or called
commands instead of being just binary numbers. It also uses symbols to describe field of instructions.
Every aspect of machine variable in program, assembly language uses one statement per machine
instruction. It managed explicitly all instruction like register allocation, call, stack, timer, jump, loop etc.
To understand the assembly language computer must require an assembler which takes a part in
between assembly language and computer system to convert the assembly instructions into the machine
language. This assembler is software or a set of program which translates assemble language
programming instruction into the machine language. For example;
LOAD

BASEPAY

ADD

OVERPAY

STORE

GROSSPAY

Advantages of Assembly language:


There have many advantage of assembly level language; some of them are listed below;

It is easily understood by human because it is uses statements instead of binary digits.


To develop a program it takes less time.
Debugging and troubleshoot is easy due to easily find error.
Its a portable language.

Disadvantages of Assembly language:


Some of the disadvantages of assembly level language are listed below;

Its a machine dependent language due to that program design for one machine no use
of other machine.
Sometime its hard to understand the statement or command use.

High-level language (Third Generation):

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 7 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


High level language is the upper level language and also known as third generation programming
language. It does consider as high level because, which language comes under this category are closer
to human languages. Hence this is highly understood programming language by human. There have
many examples of high level languages such as, FORTRAN, Pascal, C, C++, JAVA, ADA, COBOL, LISP,
Prolog etc.
The first high level programming language was written in 1950s. Those programs written in high level
language must require software or a set of program to translate that program into machine
understandable. This software called compiler and/or interpreter. The main job of compiler and
translator is to take the source code of the program and convert that code into the machine understood
code.
Advantages of high level language:
There have many advantage of high level language; some of them are listed below;

In this instructions and commands much easier to remember by programmer.


Its logic and structure are much easier to understand.
Debugging is easier compare to other languages.
Less time consuming to writing new programs.
HLL are described as being portable language.

Disadvantages of high level language:


Some of the disadvantages of high level language are listed below;

HLL programming language take more space compare to other MLL (machine level
language) and/or ALL (Assembly level language).
This programming language execute slowly.

Difference between a Compiler and an Interpreter:


No Compiler
1
Compiler Takes Entire program as input
2
Intermediate Object Code is Generated
3
Conditional Control Statements are
Executes faster
4
Memory Requirement : More (Since Object
Code is Generated)
5
Program need not be compiled every time
6
7

Interpreter
Interpreter Takes Single instruction as input .
No Intermediate Object Code is Generated
Conditional Control Statements are Executes
slower
Memory Requirement is Less

Every time higher level program is converted into


lower level program
Errors are displayed after entire program is Errors are displayed for every instruction
checked
interpreted (if any)
Example : C Compiler
Example : BASIC

Explanation : Compiler Vs Interpreter


Just understand the concept of the compiler and interpreter
We give complete program as input to the compiler. Our program is in the human readable
format.
Human readable format undergoes many passes and phases of compiler and finally it is
converted into the machine readable format.
However interpreter takes single line of code as input at a time and execute that line. It will
terminate the execution of the code as soon as it finds the error.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 8 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Memory requirement is less in Case of interpreter because no object code is created in case of
interpreter.

Reference:
[1] https://en.wikipedia.org/wiki/Programming_language
[2] http://er.yuvayana.org/definition-classification-of-computer-programming-languages/
[3] http://www.c4learn.com/c-programming/compiler-vs-interpreter/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 9 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary Text for Students


Classification of Programming Languages Computer programming language can be classified into two
major categories:
Low Level
High Level
Low Level Languages
The languages which use only primitive operations of the computer are known as low language. In
these languages, programs are written by means of the memory and registers available on the
computer. As we all know that the architecture of computer differs from one machine to another, so
far each type of computer there is a separate low level programming language. In the other words,
Programs written in one low level language of one, architectural cant be ported on any other machine
dependent languages. Examples are Machine Language and Assembly Language.
Machine Language
In machine language program, the computation is based on binary numbers. All the instructions
including operations, registers, data and memory locations are given in there binary equivalent.
The machine directly understands this language by virtue of its circuitry design so these programs are
directly executable on the computer without any translations. This makes the program execution very
fast. Machine languages are also known as first generation languages.
A typical low level instruction consists essentially of two parts:
An Operation Part :
Specifies operation to be performed by the computer, also known as Opcode.
An Address Part :
Specifies location of the data on which operation is to be performed.
Advantages
Machine language makes most efficient use of computer system resources like storage, registers, etc.
the instruction of a machine language program are directly executable so there is no need of
translators. Machine language instruction can be used to manipulate the individual bits in a computer
system with high execution speed due to direct manipulation of memory and registers.
Drawbacks
Machine languages are machine dependent and, therefore, programs are not portable from one
computer to other. Programming in machine language usually results in poor programmer
productivity. Machine languages require programmers to control the use of each register in the
computers Arithmetic Logic Unit and computer storage locations must be addressed directly, not
symbolically. Machine language requires a high level of programming skill which increases
programmer training costs. Programs written in machine language are more error prone and difficult
to debug because it is very difficult to remember all binary equivalent of register, opcode, memory
location, etc. program size is comparatively very big due to non-use of reusable codes and use of very
basic operations to do a complex computation.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 10 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Assembly Language
Assembly language are also known as second generation languages. These languages substitutes
alphabetic or numeric symbols for the binary codes of machine language. That is, we can use
mnemonics for all opcodes, registers and for the memory locations which provide us with a facility to
write reusable code in the form of macros. Has two parts, one is macro name and the other is macro
body which contains the line of instructions. A macro can be called at any point of the program by its
name to use the instruction. A macro can be called at any point of the program by its name to use the
instructions given in the macro repetitively.
These language require a translator known as Assembler for translating the program code written in
assembly language to machine language. Because computer can interpret only the machine code
instruction, once the translation is completed the program can be executed.
Advantages
Assembly language provide optimal use of computer resources like registers and memory because of
direct use of these resources within the programs. Assembly language is easier to use than machine
language because there is no need to remember or calculate the binary equivalents for opcode and
registers. An assembler is useful for detecting programming errors. Assembly language encourages
modular programming which provides the facility of reusable code, using macro.
Drawbacks
Assembly language programs are not directly executable due to the need of translation. Also, these
languages are machine dependent and, therefore, not portable from one machine to another.
Programming in assembly language requires a high level of programming skills and knowledge of
computer architecture of the particular machine.
High Level Languages (HLL)
All high level language are procedure-oriented language and are intended to be machine independent.
Programs are written in statements akin to English language, a great advantage over mnemonics of
assembly languages require languages use mnemonics of assembly language. That is, the high level
languages use natural language like structures. These languages require translators (compilers and
interpreters) for execution. The programs written in a high level language can be ported on any
computer, that is why known they are known as machine independent. The early highlevel language
come in third generation of languages, COBOL, BASIC, APL, etc.
These languages enable the programmer to write instruction using English words and familiar
mathematical symbols which makes it easier than technical details of the computer. It makes the
programs more readable too.
Procedures
Procedures are the reusable code which can be called at any point of the program. Each procedure is
defined by a name and set of instructions accomplishing a particular task. The procedure can be called
by its name with the list of required parameters which should pass to tat procedure.
Advantages of High Level Languages
These are the third generation languages. These are procedure-oriented languages and are machine
independent. Programs are written in English like statements. As high level languages are not directly
executable, translators(compilers and interpreters) are used to convert them in machine language
equivalent.
Advantages
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 11 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

1)These are easier to learn than assembly language.


2)Les time is required to write programs.
3)These provides better documentation.
4)These are easier to maintain.
5)These have an extensive vocabulary.
Limitation of Programming language
1)A long sequence statements is to be written for every program.
2)Additional memory space is required for storing compiler or interpreter.
3)Execution time is very high as the HLL programs are not directly executable.
Reference:
[1] https://www.classle.net/#!/classle/content-page/classification-programming-language/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 12 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary Text for Students


Interpreter Vs Compiler : Difference Between Interpreter and Compiler
We generally write a computer program using a high-level language. A high-level language is one which
is understandable by us humans. It contains words and phrases from the English (or other) language.
But a computer does not understand high-level language. It only understands program written in 0's
and 1's in binary, called the machine code. A program written in high-level language is called a source
code. We need to convert the source code into machine code and this is accomplished my compilers and
interpreters. Hence, a compiler or an interpreter is a program that converts program written in highlevel language into machine code understood by the computer.
The difference between an interpreter and a compiler is given below:
Interpreter
Compiler
Translates program one statement at a time.
Scans the entire program and translates it as a
whole into machine code.
It takes less amount of time to analyze the source It takes large amount of time to analyze the source
code but the overall execution time is slower.
code but the overall execution time is
comparatively faster.
No intermediate object code is generated, hence Generates intermediate object code which further
are memory efficient.
requires linking, hence requires more memory.
Continues translating the program until the first It generates the error message only after scanning
error is met, in which case it stops. Hence the whole program. Hence debugging is
debugging is easy.
comparatively hard.
Programming language like Python, Ruby use Programming language like C, C++ use compilers.
interpreters.

Reference:
[1] http://www.programiz.com/article/difference-compiler-interpreter

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 13 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Difference between Compiler, Interpreter and Assembler

Lets get some of our concepts clear before to head on to programming in java.This and perhaps
next few posts will help you clear some computer programming concepts.
Both compiler and interpreter convert human readable high level language like Java,C++ etc
into machine language but there is difference in the way both function.So lets take a look to
understand the differences.
Difference between Compiler and Interpreter

Compiler scans the entire program once and then converts it into machine language
which can then be executed by computer's processor.In short compiler translates the
entire program in one go and then executes it. Interpreter on the other hand first
converts high level language into an intermediate code and then executes it line by line.
This intermediate code is executed by another program.

The execution of program is faster in compiler than interpreter as in interpreter code is


executed line by line.
Compiler generates error report after translation of entire code whereas in case of
interpreter once an error is encountered it is notified and no further code is scanned.
Example Python is an interpreted language whereas C,C++ are compiled languages.Java
however uses both compiler and interpreter.We will look into how this exactly works in
case of java in next post.
Diagrammatic representation-

What is Assembler?

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 14 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Assembler is used for converting the code of low level language (assembly language) into
machine level language.If you have worked on microprocessors like 8085 and 8086 the module
which converts assembly language into machine language is nothing but Assembler.
Java - Compiled or interpreted?

As our basics are now clear lets get on to Java. Well you must have heard that Java is both
compiled and interpreted language. When it comes to the question - How Java works? It goes
something like below

When you run javac HelloWorld.java java compiler is invoked which converts human
readable code(Contents of .java file) to java byte codes(intermediate form). This
bytecodes are stored in a special file(called Class file) with .class extension.
Finally when you run java HelloWorld java interpreter is invoked which reads these
bytecodes line by line, convert it into machine language and execute it.

This is why Java is called as both compiled as well as interpreted language.


Reference:
[1]
http://opensourceforgeeks.blogspot.com/2013/03/difference-between-compilerinterpreter.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 15 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Discuss the differences between a procedural programming language and an object
oriented programming language. 10 October-2010 April-2013
Difference Between Procedure Oriented Programming (POP) & Object Oriented Programming (OOP):
Following are some important differences between Procedure Oriented Programming and Object
Oriented Programming:

Divided Into
Importance

Approach
Access
Specifiers
Data Moving

Expansion
Data Access

Data Hiding
Overloading

Examples

Procedure Oriented Programming


In POP, program is divided into small
parts called functions.
In POP,Importance is not given to data
but to functions as well as sequence of
actions to be done.
POP follows Top Down approach.
POP does not have any access specifier.
In POP, Data can move freely from
function to function in the system.
To add new data and function in POP is
not so easy.
In POP, Most function uses Global data for
sharing that can be accessed freely from
function to function in the system.
POP does not have any proper way for
hiding data so it is less secure.
In POP, Overloading is not possible.

Example of POP are : C, VB, FORTRAN,


Pascal.

Object Oriented Programming


In OOP, program is divided into parts
called objects.
In OOP, Importance is given to the data
rather than procedures or functions
because it works as a real world.
OOP follows Bottom Up approach.
OOP has access specifiers named Public,
Private, Protected, etc.
In OOP, objects can move and
communicate with each other through
member functions.
OOP provides an easy way to add new
data and function.
In OOP, data can not move easily from
function to function,it can be kept public
or private so we can control the access of
data.
OOP provides Data Hiding so provides
more security.
In OOP, overloading is possible in the
form of Function Overloading and
Operator Overloading.
Example of OOP are : C++, JAVA, VB.NET,
C#.NET.

Reference:
[1]
http://freefeast.info/general-it-articles/difference-between-procedure-oriented-programmingand-object-oriented-programming-procedure-oriented-programming-vs-object-orientedprogramming/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 16 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary Text For Students


Simple comparison between Object-oriented Programming and Procedural Programming
A simple way to compare both programming methods is to think of Object-oriented Programming
as learn to read picture book. As children see pictures of simple objects like a house or picture they know
that throughout the book when they see a picture of the house it represents the word house. The
children can then read through the book as words are substituted throughout the story with pictures.
In Object-oriented Programming the classes could represent the pictures in the learn to read books. A
house could represent a class and anything the developer wants to have included to describe that house
like the color, size, number of bathrooms etc.
In Procedural Programming the learn to read book would be words on the page without pictures to help
guide the young learner through the book. If the story was changed in the beginning of the book it could
disrupt or make the story later on in the book not make any sense. Although learning to read the book
would make programming with Procedural Programming simple, it would make it difficult for other
readers in the case of the book or programmers in the case of Procedural Programming to add to the
story.
Procedural Programming also uses different methods throughout the code than Object-oriented
Programming.
As an example Object-oriented Programming uses methods where Procedural Programming uses
procedures.
Object-oriented Programming uses objects where Procedural Programming uses records.
Object-oriented Programming uses classes where Procedural Programming uses modules and Objectoriented Programming uses messages where Procedural Programming uses procedure calls.
In addition, Object-oriented Programming uses data fields where Procedural Programming uses
procedures. A chart has been provided below to illustrate the differences between the two:
Procedural
Object-oriented
procedure
method
record
object
module
class
procedure call
message

Reference:
[1]
https://neonbrand.com/website-design/procedural-programming-vs-object-orientedprogramming-a-review/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 17 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Distinguish between machine language, assembly language and high level language.
Mention the types of errors that can be occur in a computer program. 6+4 April-2008
Difference between machine, assembly and high level language:
Programming languages are classified as :
1. Machine language:
2. Assembly language:
3. High level language :
Machine language :- the language of 0s and 1s is called as machine language. The machine language is
system independent because there are different set of binary instruction for different types of computer
systems .
Limitations of machine languages :
It is very tedious and error prone process of writing programs in machine languages .
Assembly languages: it is low level programming language in which the sequence of 0s and 1s are
replaced by mnemonic (ni-monic) codes. Typical instruction for addition and subtraction .
Example :- add for addition , sub for subtraction etc
Since our system only understand the language of 0s and 1s . Therefore a system program is known as
assembler . Which is designed to translate an assembly language program into the machine language
program.
High level language :- high level languages are english like statements and programs . Written in these
languages are needed to be translated into machine language before to their execution using a system
software compiler .
Program written in high level languages are much easier to maintain and modified .
High level language program is also called source code.
Machine language program is also called object code.
Types Of Errors That Can Be Occur In A Computer Program:
Even the most experienced programmers make mistakes, and knowing how to debug an application and
find those mistakes is an important part of programming. Before you learn about the debugging process,
however, it helps to know the types of bugs that you will need to find and fix.
Programming errors fall into three categories: compilation errors, run-time errors, and logic errors. The
techniques for debugging each of these are covered in the next three lessons.
Compilation Errors
Compilation errors, also known as compiler errors, are errors that prevent your program from running.
When you press F5 to run a program, Visual Basic compiles your code into a binary language that the
computer understands. If the Visual Basic compiler comes across code that it does not understand, it
issues a compiler error.
Most compiler errors are caused by mistakes that you make when typing code. For example, you might
misspell a keyword, leave out some necessary punctuation, or try to use an End If statement without
first using an If statement.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 18 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Fortunately the Visual Basic Code Editor was designed to identify these mistakes before you try to run
the program. You will learn how to find and fix compilation errors in the next lesson, Finding and Getting
Rid of Compiler Errors.
Run Time Errors:
Run-time errors are errors that occur while your program runs. These typically occur when your
program attempts an operation that is impossible to carry out.
An example of this is division by zero. Suppose you had the following statement:
Speed = Miles / Hours
If the variable Hours has a value of 0, the division operation fails and causes a run-time error. The
program must run in order for this error to be detected, and if Hours contains a valid value, it will not
occur at all.
When a run-time error does occur, you can use the debugging tools in Visual Basic to determine the
cause. You will learn how to find and fix run-time errors in the lesson It Doesn't Work! Finding and
Eliminating Run-Time Errors.
Logic Errors
Logic errors are errors that prevent your program from doing what you intended it to do. Your code
may compile and run without error, but the result of an operation may produce a result that you did not
expect.
For example, you might have a variable named FirstName that is initially set to a blank string. Later in
your program, you might concatenate FirstName with another variable named LastName to display a
full name. If you forgot to assign a value to FirstName, only the last name would be displayed, not the
full name as you intended.
Logic errors are the hardest to find and fix, but Visual Basic has debugging tools that make this job easier,
also. You will learn how to find and fix logic errors in What? It Wasn't Supposed To Do That! Finding
Logic Errors.

Reference:
[1] http://studentstudyhub.blogspot.com/2012/10/difference-between-machineassembly-and.html
[2] https://msdn.microsoft.com/en-us/library/s9ek7a19%28v=vs.90%29.aspx

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 19 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary Texts for Students


Types of Program Errors
Program errors are also referred to as program bugs.
A C program may have one or more of four types of errors:

Syntax errors (Compiler errors or Compile-time errors)


Linker Errors
Runtime errors
Logic errors

Usually, the errors become more difficult to find and fix as you move down the above list.
Syntax errors
Syntax errors represent grammar errors in the use of the programming language. Common examples
are:

Misspelled variable and function names


Missing semicolons
Unmatched parentheses, square brackets, and curly braces
Using a variable that has not been declared
Incorrect format in selection and loop statements

Syntax errors are the easiest to find and fix. Over the years, compiler developers have worked hard to
make compilers smarter so that they can catch errors at compile time that might otherwise turn out to
be runtime errors.
Examples:
1. Simple statement not terminated by semicolon:

2. Using a variable before it is declared:

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 20 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

3. Missing closing parenthesis, ) , in the printf satatement:

Linker errors

Linker errors are generated when the linker encounters what looks like a function call; but it
cannot find a function with that name. This is usually caused by misspelling a C standard
function (like main) or not including the header file for a function.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 21 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Examples:
1. Misspelling a standard C function:

2. Not including the header file for a function:

Note: Dev C++ has an option that automatically includes standard header files. It is not recommended
to use this option, as it is CPU-intensive. To turn off this option use the menus: Tools Compiler
Options Settings Linker and set "Do not use standard system startup files or libraries" to Yes:

With the option turned off, not including a standard header file in your program will generate a linker
error:

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 22 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Runtime errors

A type of error that occurs during the execution of a program is known as run-time error.
Runtime errors may crash your program when you run it. Runtime errors occur when a
program with no syntax errors directs the computer to execute an illegal operation. Common
examples are:

Trying to divide by a variable that contains a value of zero

Trying to open a file that does not exist

There is no way for the compiler to know about these kinds of errors when the program is compiled.
Runtime errors are commonly due to wrong input from the user. Runtime errors are usually more
difficult to find and fix than syntax errors.

To find the source of a run-time error in a program, usually a software called debugger is used.
Example: When the following program is executed and the user inputs 0 for num2, a run-time
error occurs due to division by zero in the expression num1 / num2
#include <stdio.h>
#include <stdlib.h>

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 23 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


int main(void) {
int num1, num2;
printf("Enter the first integer: ");
scanf("%d", &num1);
printf("\nEnter the second integer: ");
scanf("%d", &num2);
printf("\n%d + %d = %d", num1, num2, num1 + num2);
printf("\n%d / %d = %d", num1, num2, num1 / num2);
printf("\n%d * %d = %d\n", num1, num2, num1 * num2);
system("PAUSE");
return 0;
}

Logic errors

Logic errors occur when a programmer implements the algorithm for solving a problem
incorrectly. A statement with logical error may produce unexpected and wrong results in the
program. Common examples are:

Multiplying when you should be dividing


Adding when you should be subtracting
Opening and using data from the wrong file
Displaying the wrong message

Logic errors are the hardest to find and fix because:

The compiler does not detect these errors


There is no indication of error when the program is executed.
The program may produce correct results for some input data and wrong results for other
input data.

Logic errors can only be detected by examining the program thoroughly. This is usually done by using
a debugger.
Example: The following program has a logic error in the 3rd printf statement

#include <stdio.h>
#include <stdlib.h>

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 24 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


int main(void) {
int num1, num2;
printf("Enter the first integer: ");
scanf("%d", &num1);
printf("\nEnter the second integer: ");
scanf("%d", &num2);
printf("\n%d + %d = %d\n", num1, num2, num1 * num2);
system("PAUSE");
return 0;
}
Notice that the program produces correct results for some input (num1 = 2, num2 = 2 and num1 = 0,
num2 = 0) and wrong results for others:

Exercise: Copy and paste the program below in Dev C++ editor. Save the program using an
appropriate name. Determine, classify and correct all errors in the program by compiling and
executing the program:
#include <stdio.h>;
#include <stdlib.h>;
int main(void); {
int num1;
printf('Enter the first integer: ');
scanf("%d", &num1);
printf("\nEnter the second integer: ";
scanf("%d", &num2);
Printf("\n%d * %d = %c\n", num1, num2, num1 + num2);
system("PAUSE";
return 0;
}
Reference:
[1] http://faculty.kfupm.edu.sa/ICS/said/ics103_101/Lab02%20Supplement2Types%20of%20Program%20Errors.doc

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 25 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: State out the differences between high level and assembly language.

Features of high level language:


- High level languages are easily understandable.
- The programs that are developed in high level language are portable.
- In case of high level languages debugging of the code is easy and the program written is not machine
dependent.
Features of Assembly language:
- Although Assembly level languages are not easy to understand they are relatively easier as compared
to machine level languages.
- The programs written in this language are not portable and the debugging process is also not very
easy.
- The programs developed in assembly language are thoroughly machine dependent.
Reference:
[1] http://www.careerride.com/view.aspx?id=2276

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 26 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write the advantages and disadvantages of using Compiler and Interpreter. 5 Marks
The advantages of both implementation methods compiling and interpreting are as follows:
Advantages of using compiler: Since compiler converts the program to native code of the target machine (object code), faster
performance can be expected.
There is a scope for code optimisation.
Advantages of using interpreter: Process of execution can be done in a single stage. There is no need of a compilation stage.
Alteration of codes possible during runtime.
Really useful for debugging the codes (because source code execution can be analyzed in an IDE)
Facilitates interactive code development.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 27 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What is Object Oriented Programming? October-2007
Object-oriented programming (OOP):
Object-oriented programming (OOP) is a programming paradigm based on the concept
of "objects", which are data structures that contain data, in the form of fields, often known as attributes;
and code, in the form of procedures, often known as methods. A distinguishing feature of objects is that
an object's procedures can access and often modify the data fields of the object with which they are
associated (objects have a notion of "this" or "self"). In OO programming, computer programs are
designed by making them out of objects that interact with one another. There is significant diversity in
object-oriented programming, but most popular languages are class-based, meaning that objects are
instances of classes, which typically also determines their type.
Many of the most widely used programming languages are multi-paradigm
programming languages that support object-oriented programming to a greater or lesser degree,
typically in combination with imperative, procedural programming. Significant object-oriented
languages include Common Lisp, Python, C++, Objective-C, Smalltalk, Delphi, Java, Swift, C#, Perl, Ruby,
and PHP.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 28 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question-01: Explain with examples the concept of (i) Encapsulation (ii) Inheritance (iii) Operator
Overloading (iv) Function overloading and (v) Friend Function in object oriented programming. 10
October-2014 April-2014
Encapsulation:
Encapsulation is the mechanism that binds together code and the data it manipulates,
and keeps both safe from outside interference and misuse. In an object-oriented language, code and data
may be combined in such a way that a self-contained "black box" is created. When code and data are
linked together in this fashion, an object is created. In other words, an object is the device that supports
encapsulation.
Within an object, code, data, or both may be private to that object or public. Private
code or data is known to and accessible only by another part of the object. That is, private code or data
may not be accessed by a piece of the program that exists outside the object. When code or data is public,
other parts of your program may access it even though it is defined within an object. Typically, the public
parts of an object are used to provide a controlled interface to the private elements of the object.
For all intents and purposes, an object is a variable of a user-defined type. It may seem
strange that an object that links both code and data can be thought of as a variable. However, in objectoriented programming, this is precisely the case. Each time you define a new type of object, you are
creating a new data type. Each specific instance of this data type is a compound variable.
Polymorphism:
Object-oriented programming languages support polymorphism, which is characterized
by the phrase "one interface, multiple methods." In simple terms, Polymorphism is the attribute that
allows one interface to control access to a general class of actions. The specific action selected is
determined by the exact nature of the situation.
For example, you might have a program that defines three different types of stacks. One stack is used for
integer values, one for character values, and one for floating-point values. Because of polymorphism,
you can define one set of names, push() and pop() , that can be used for all three stacks. In your program
you will create three specific versions of these functions, one for each type of stack, but names of the
functions will be the same. The compiler will automatically select the right function based upon the data
being stored.
Thus, the interface to a stackthe functions push() and pop() are the same no matter which type of
stack is being used. The individual versions of these functions define the specific implementations
(methods) for each type of data.
Polymorphism helps reduce complexity by allowing the same interface to be used to access a general
class of actions. It is the compiler's job to select the specific action (i.e., method) as it applies to each
situation. You, the programmer, don't need to do this selection manually. You need only remember and
utilize the general interface.
The first object-oriented programming languages were interpreters, so polymorphism was, of course,
supported at run time. However, C++ is a compiled language. Therefore, in C++, both run-time and
compile-time polymorphism are supported.
Inheritance:
Inheritance is the process by which one object can acquire the properties of another object.
This is important because it supports the concept of classification. If you think about it, most knowledge
is made manageable by hierarchical classifications. For example, a Red Delicious apple is part of the
classification apple, which in turn is part of the fruit class, which is under the larger class food. Without
the use of classifications, each object would have to define explicitly all of its characteristics. However,
through the use of classifications, an object need only define those qualities that make it unique within

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 29 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


its class. It is the inheritance mechanism that makes it possible for one object to be a specific instance of
a more general case. As you will see, inheritance is an important aspect of object-oriented programming.
Operator Overloading:
In programming, operator overloadingless commonly known as operator ad hoc
polymorphismis a specific case of polymorphism, where different operators have different
implementations depending on their arguments. Operator overloading is generally defined by the
language, the programmer, or both.
Closely related to function overloading is operator overloading. In C++, you can overload most
operators so that they perform special operations relative to classes that you create. For example, a class
that maintains a stack might overload + to perform a push operation and to perform a pop. When an
operator is overloaded, none of its original meanings are lost. Instead, the type of objects it can be
applied to is expanded.
The ability to overload operators is one of C++'s most powerful features. It allows the full integration
of new class types into the programming environment. After overloading the appropriate operators, you
can use objects in expressions in just the same way that you use C++'s built-in data types. Operator
overloading also forms the basis of C++'s approach to I/O.
You overload operators by creating operator functions. An operator function defines the operations that
the overloaded operator will perform relative to the class upon which it will work. An operator function
is created using the keyword operator. Operator functions can be either members or nonmembers of a
class. Nonmember operator functions are almost always friend functions of the class, however. The way
operator functions are written differs between member and nonmember functions.
Examples
In this case, the addition operator is overloaded to allow addition on a user-defined type "Time" (in
C++):
Time operator+(const Time& lhs, const Time& rhs)
{
Time temp = lhs;
temp.seconds += rhs.seconds;
temp.minutes += temp.seconds / 60;
temp.seconds %= 60;
temp.minutes += rhs.minutes;
temp.hours += temp.minutes / 60;
temp.minutes %= 60;
temp.hours += rhs.hours;
return temp;
}
Addition is a binary operation, which means it has two operands. In C++, the arguments being passed
are the operands, and the temp object is the returned value.
Function Overloading:
Function overloading is the process of using the same name for two or more functions.
The secret to overloading is that each redefinition of the function must use either different types of
parameters or a different number of parameters. It is only through these differences that the compiler
knows which function to call in any given situation.
For example, this program overloads myfunc() by using different types of parameters.
#include <iostream>
using namespace std;
int myfunc(int i); // these differ in types of parameters
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 30 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


double myfunc(double i);
int main()
{
cout << myfunc(10) << " "; // calls myfunc(int i)
cout << myfunc(5.4); // calls myfunc(double i)
return 0;
}
double myfunc(double i)
{
return i;
}
int myfunc(int i)
{
return i;
}
Friend Function:
In object-oriented programming, a friend function that is a "friend" of a given class is
allowed access to private and protected data in that class that it would not normally be able to as if the
data was public. Normally, a function that is defined outside of a class cannot access such information.
Declaring a function a friend of a class allows this, in languages where the concept is supported.
A friend function is declared by the class that is granting access, explicitly stating what
function from a class is allowed access. A similar concept is that of friend class.
It is possible to grant a non-member function access to the private members of a class by using a friend.
A friend function has access to all private and protected members of the class for which it is a friend. To
declare a friend function, include its prototype within the class, preceding it with the keyword friend.
Consider this program:
#include <iostream>
using namespace std;
class myclass {
int a, b;
public:
friend int sum(myclass x);
void set_ab(int i, int j);
};
void myclass::set_ab(int i, int j)
{
a = i;
b = j;
}
// Note: sum() is not a member function of any class.
int sum(myclass x)
{
/* Because sum() is a friend of myclass, it can
directly access a and b. */
return x.a + x.b;
}
int main()
{
myclass n;
n.set_ab(3, 4);
cout << sum(n);
return 0;
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 31 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


}
In this example, the sum() function is not a member of myclass. However, it still has full access to its
private members. Also, notice that sum() is called without the use of the dot operator. Because it is not
a member function, it does not need to be (indeed, it may not be) qualified with an object's name.
There are some circumstances in which friend functions are quite valuable.
First, friends can be useful when you are overloading certain types of operators.
Second, friend functions make the creation of some types of I/O functions easier.
The third reason that friend functions may be desirable is that in some cases, two or more classes
may contain members that are interrelated relative to other parts of your program.
Question: Explain the Three Properties Of An Object Oriented Programming Language. What are the steps
that are followed to debug a program? 6 October-2013
Three Properties Of An Object Oriented Programming Language:
Three properties of an Object Oriented Programming are as follows:
1. Encapsulation
2. Polymorphism
3. Inheritance
The above three properties are described below:
Encapsulation:
Encapsulation is the mechanism that binds together code and the data it manipulates,
and keeps both safe from outside interference and misuse. In an object-oriented language, code and data
may be combined in such a way that a self-contained "black box" is created. When code and data are
linked together in this fashion, an object is created. In other words, an object is the device that supports
encapsulation.
Within an object, code, data, or both may be private to that object or public. Private
code or data is known to and accessible only by another part of the object. That is, private code or data
may not be accessed by a piece of the program that exists outside the object. When code or data is public,
other parts of your program may access it even though it is defined within an object. Typically, the public
parts of an object are used to provide a controlled interface to the private elements of the object.
For all intents and purposes, an object is a variable of a user-defined type. It may seem
strange that an object that links both code and data can be thought of as a variable. However, in objectoriented programming, this is precisely the case. Each time you define a new type of object, you are
creating a new data type. Each specific instance of this data type is a compound variable.
Polymorphism:
Object-oriented programming languages support polymorphism, which is characterized
by the phrase "one interface, multiple methods." In simple terms, Polymorphism is the attribute that
allows one interface to control access to a general class of actions. The specific action selected is
determined by the exact nature of the situation.
For example, you might have a program that defines three different types of stacks. One stack is used for
integer values, one for character values, and one for floating-point values. Because of polymorphism,
you can define one set of names, push() and pop() , that can be used for all three stacks. In your program
you will create three specific versions of these functions, one for each type of stack, but names of the
functions will be the same. The compiler will automatically select the right function based upon the data
being stored.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 32 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Thus, the interface to a stackthe functions push() and pop() are the same no matter which type of
stack is being used. The individual versions of these functions define the specific implementations
(methods) for each type of data.
Polymorphism helps reduce complexity by allowing the same interface to be used to access a general
class of actions. It is the compiler's job to select the specific action (i.e., method) as it applies to each
situation. You, the programmer, don't need to do this selection manually. You need only remember and
utilize the general interface.
The first object-oriented programming languages were interpreters, so polymorphism was, of course,
supported at run time. However, C++ is a compiled language. Therefore, in C++, both run-time and
compile-time polymorphism are supported.
Inheritance:
Inheritance is the process by which one object can acquire the properties of another object.
This is important because it supports the concept of classification. If you think about it, most knowledge
is made manageable by hierarchical classifications. For example, a Red Delicious apple is part of the
classification apple, which in turn is part of the fruit class, which is under the larger class food. Without
the use of classifications, each object would have to define explicitly all of its characteristics. However,
through the use of classifications, an object need only define those qualities that make it unique within
its class. It is the inheritance mechanism that makes it possible for one object to be a specific instance of
a more general case. As you will see, inheritance is an important aspect of object-oriented programming.
Steps that are followed to Debug a Program:
Following are seven steps to debug a program:
Step 1. Identify the error.
Step 2. Find the error.
Step 3. Analyze the error.
Step 4. Prove your analysis
Step 5. Cover lateral damage.
Step 6. Fix the error.
Step 7. Validate the solution.
Reference:
[1] http://www.makinggoodsoftware.com/2009/06/14/7-steps-to-fix-an-error/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 33 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What is Source Program and Object program? Explain the differences between a source
program and an object program. 5 April-2011 October-2011
Source program and object program are two types of programs found in computer programming. Source
program is typically a program with human readable machine instructions written by a programmer.
Object program is typically a machine executable program created by compiling a source program.
What is Source Program?
Source program is a code written by a programmer usually using a higher level language, which is easily
readable by the humans. Source programs usually contain meaningful variable names and helpful
comments to make it more readable. A source program cannot be directly executed on a machine. In
order to execute it, the source program is compiled using a compiler (a program, which transforms
source programs to executable code). Alternatively, using an interpreter (a program that executes a
source program line by line without pre-compilation) a source program may be executed on the fly.
Visual Basic is an example of a compiled language, while Java is an example of an interpreted language.
Visual Basic source files (.vb files) are compiled to .exe code, while Java source files (.java files) are first
compiled (using javac command) to bytecode (an object code contained in .class files) and then
interpreted using the java interpreter (using java command). When software applications are
distributed, typically they will not include source files. However, if the application is open source, the
source is also distributed and the user gets to see and modify the source code as well.
What is Object Program?
Object program is usually a machine executable file, which is the result of compiling a source file using
a compiler. Apart from machine instructions, they may include debugging information, symbols, stack
information, relocation and profiling information. Since they contain instructions in machine code, they
are not easily readable by humans. But sometimes, object programs refer to an intermediate object
between source and executable files. Tools known as linkers are used to link a set of objects in to an
executable (e.g. C language). As mentioned above .exe files and bytecode files are object files produced
when using Visual Basic and Java respectively. .exe files are directly executable on windows platform,
while bytecode files need an interpreter for execution. Most software applications are distributed with
the object or executable files only. Object or executable files can be converted back to its original source
files by decompilation. For example, java .class files (bytecode) can be decompiled using Decompiler
tools in to its original .java files.
What is the difference between Source Program and Object Program?
Source program is a program written by a programmer, while an object program is generated by a
compiler using one or more source files as input. Source files are written in higher level languages such
as Java or C (so they are easily readable by humans), but object programs usually contain lower level
languages such as assembly or machine code (so they are not human readable). Source files can be either
compiled or interpreted for execution. Decompilers can be used to convert object programs back to its
original source file(s). It is important to note that the terms source program and object program are
used as relative terms. If you take a program transformation program (like a compiler), what goes in is
a source program and what comes out is an object program. Therefore an object program produced by
one tool can become a source file for another tool.
Reference:
[1] http://www.differencebetween.com/difference-between-source-program-and-vs-object-program/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 34 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Explain with examples the syntax errors, runtime errors, and logical errors that you can
encounter when writing computer programs. What are the steps that are followed to debug these
problems of a program? 10 April-2014
Syntax Errors:
Syntax or format errors are a major problem for most beginning programmers using
languages such as C++, Java, and C#. A syntax error occurs when the programmer fails to obey one of
the grammar rules of the language. Typically this involves things like using the wrong case, putting
punctuation where it is not supposed to be, failing to put punctuation where it is supposed to be, etc.
One of the great things about Alice as a programming language for beginning programmers is that the
drag and drop paradigm used in Alice largely eliminates syntax errors. With Alice, new programming
students are free to concentrate on solving the stated problem without too much worry about how to
satisfy the syntax requirements. Syntax errors probably won't be a problem for you as long as you are
programming using Alice.
Runtime Errors:
Runtime error occurs whenever the program instructs the computer to do something that it is either
incapable or unwilling to do. Since there are a near infinite number of things that fall in this category,
there are a near infinite number of ways to write programs that cause runtime errors.
In Alice, runtime errors commonly occur when statements are written in the wrong order, or perhaps
the order is modified by dragging statements up and down the screen after they are written. Another
common cause of runtime errors results from the construction of instructions that the computer is
unable to carry out.
The classical divide by zero error
The classical way to demonstrate a runtime error is to instruct the computer to divide any number by
the value zero. Any value divided by 0 produces an infinitely large result, which is too large to be
accommodated by the computer. Therefore, in most cases, the computer will tell you that it is unable to
perform that operation.
Logical Errors:
Logic errors are usually the most difficult kind of errors to find and fix, because there
frequently is no obvious indication of the error. Usually the program runs successfully. It simply doesn't
behave as it should. In other words, it simply doesn't produce the correct answers.
The Causes Of Logic Errors
Logic errors usually result from one or some combination of the following three causes:
You didn't understand how the program is supposed to behave.
You didn't understand the behavior of each operation that you wrote into the program.
You were careless.
Often found by an irate customer
Unfortunately, logic errors often go undetected until you receive an irate call from your customer telling
you that your program caused every employee in the company to receive too much money in their most
recent paycheck, or something similarly disastrous.
How to prevent logic errors
In an attempt to prevent logic errors, you should:
Make absolutely certain that you do understand how the program is supposed to behave.
Make absolutely certain that you do understand the behavior of every operation that you write
into your program.
Not be careless.
Implement a practice of testing, testing, and testing.
Steps That Are Followed To Debug These Problems Of A Program:
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 35 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


7 Steps to fix a bug
The correct approach to debug is to follow a very structured procedure based on repeating the same
steps for every bug, the reason for this is that bugs usually are symptoms of a much bigger problem
going on, so in order for us to uncover the real nature of the error we have to make sure we do an
exhaust and systematic revision of it.
The degree of formality when following the steps may vary depending on the bug, for critical errors is
better to document every single step in a document, for minor errors, or bugs found while coding is
just enough to follow them as a mental guideline to make sure we cover all the error.
Step 1. Identify the error.
This is an obvious step but a tricky one, sometimes a bad identification of an error can cause lots of
wasted developing time, is usual that production errors reported by users are hard to be interpreted
and sometimes the information we are getting from them is misleading.
A few tips to make sure you identify correctly the bug are.

1. See the error. This is easy if you spot the error, but not if it comes from a user, in that
case see if you can get the user to send you a few screen captures or even use remote
connection to see the error by yourself.
2. Reproduce the error. You never should say that an error has been fixed if you were not
able to reproduce it.
3. Understand what the expected behavior should be. In complex applications could be
hard to tell what should be the expected behavior of an error, but that knowledge is
basic to be able to fix the problem, so we will have to talk with the product owner,
check documentation to find this information
4. Validate the identification. Confirm with the responsible of the application that the
error is actually an error and that the expected behavior is correct. The validation can
also lead to situations where is not necessary or not worth it to fix the error.
Step 2. Find the error.
Once we have an error correctly identified, is time to go through the code to find the exact spot where
the error is located, at this stage we are not interested in understanding the big picture for the error,
we are just focused on finding it. A few techniques that may help to find an error are:

Logging. It can be to the console, file It should help you to trace the error in the code.
Debugging. Debugging in the most technical sense of the word, meaning turning on
whatever the debugger you are using and stepping through the code.
Removing code. I discovered this method a year ago when we were trying to fix a very
challenging bug. We had an application which a few seconds after performing an action
was causing the system to crash but only on some computers and not always but only
from time to time, when debugging, everything seemed to work as expected, and when
the machine was crashing it happened with many different patterns, we were
completely lost, and then it occurred to us the removing code approach. It worked
more or less like this: We took out half of the code from the action causing the machine
to crash, and we executed it hundreds of times, and the application crashed, we did the
same with the other half of the code and the application didnt crash, so we knew the
error was on the first half, we kept splitting the code until we found that the error was
on a third party function we were using, so we just decided to rewrite it by ourselves.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 36 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Step 3. Analyze the error.
This is a critical step, use a bottom-up approach from the place the error was found and analyze the
code so you can see the big picture of the error, analyzing a bug has two main goals: to check that
around that error there arent any other errors to be found (the iceberg metaphor), and to make sure
what are the risks of entering any collateral damage in the fix.
Step 4. Prove your analysis
This is a straight forward step, after analyzing the original bug you may have come with a few more
errors that may appear on the application, this step its all about writing automated tests for these
areas (is better to use a test framework as any from the xUnit family).
Once you have your tests, you can run them and you should see all them failing, that proves that your
analysis is right.
Step 5. Cover lateral damage.
At this stage you are almost ready to start coding the fix, but you have to cover your ass before you
change the code, so you create or gather (if already created) all the unit tests for the code which is
around where you will do the changes so that you will be sure after completing the modification that
you wont have break anything else. If you run this unit tests, they all should pass.
Step 6. Fix the error.
Thats it, finally you can fix the error!
Step 7. Validate the solution.
Run all the test scripts and check that they all pass.

Reference:
[1] http://www.makinggoodsoftware.com/2009/06/14/7-steps-to-fix-an-error/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 37 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary Text for Student


Syntax errors
These are errors where the compiler finds something wrong with your program, and you can't even try
to execute it. For example, you may have incorrect punctuation, or may be trying to use a variable that
hasn't been declared.
Syntax errors are the easiest to find and correct. The compiler will tell you where it got into trouble, and
its best guess as to what you did wrong. Usually the error is on the exact line indicated by the compiler,
or the line just before it; however, if the problem is incorrectly nested braces, the actual error may be at
the beginning of the nested block.
Runtime errors
If there are no syntax errors, Java may detect an error while your program is running. You will get an
error message telling you the kind of error, and a stack trace that tells not only where the error occurred,
but also what other method or methods you were in. For example,
Exception in thread "main" java.lang.NullPointerException
at Car.placeInCity(Car.java:25)
at City.<init>(City.java:38)
at City.main(City.java:49)
This says that a NullPointerException was detected in the method placeCarInCity at line 25 in Car.java,
which was called from the constructor for City at line 38 in City.java, which was called from the main
method at line 49 in City.java. Sometimes there will be additional lines describing methods in the Java
system itself; you can ignore these.
Runtime errors are intermediate in difficulty. Java tells you where it discovered that your program had
gone wrong, but you need to trace back from there to figure out where the problem originated.
Logic errors
A logic error, or bug, is when your program compiles and runs, but does the wrong thing. The Java
system, of course, has no idea what your program is supposed to do, so it provides no additional
information to help you find the error.
Ways to track down a logic error include:

Think about what the program must have done in order to produce the results it did.
This will lead you to where the error must have occurred.
Put in print statements to help you figure out what the program is actually doing.
Use a debugger to step through your program and watch what it does.

Reference:
[1] https://www.cis.upenn.edu/~matuszek/General/JavaSyntax/errors.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 38 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Name three programming languages. Using the appropriate computer program, explain the
steps involved from writing a computer program to its execution. 10 April-2003
Name of the Three Programming Languages:
1. C
2. C++
3. Java
Steps Involved From Writing a Computer Program to Its Execution:
There are various steps involved in producing a computer program for a particular application. These
steps are independent of which computer or programming language that is used and require the
existence of certain facilities upon the computer. The steps are:

Study the requirement specification for the application. It is important that the requirements of
the application should be well specified. Before starting to design a program for the application
it is necessary that the requirement specification is complete and consistent. For example a
requirement specification that says `write a program to solve equations' is obviously incomplete
and you would have to ask for more information on `what type of equations?', `how many
equations?', `to what accuracy?' etc.
Analyse the problem and decide how to solve it. At this stage one has to decide on a method
whereby the problem can be solved, such a method of solution is often called an Algorithm.
Translate the algorithm produced at the previous step into a suitable high-level language. This
written form of the program is often called the source program or source code. At this stage the
program should be read to check that it is reasonable and a desk-check carried out to verify its
correctness. A programmer carries out a desk-check by entering a simple set of input values and
checking that the correct result is produced by going through the program and executing each
instruction themselves. Once satisfied that the program is reasonable it is entered into the
computer by using an Editor.
Compile the program into machine-language. The machine language program produced is called
the object code. At this stage the compiler may find Syntax errors in the program. A syntax error
is a mistake in the grammar of a language, for example C++ requires that each statement should
be terminated by a semi-colon. If you miss this semi-colon out then the compiler will signal a
syntax error. Before proceeding any syntax errors are corrected and compilation is repeated
until the compiler produces an executable program free from syntax errors.
The object code produced by the compiler will then be linked with various function libraries that
are provided by the system. This takes place in a program called a linker and the linked object
code is then loaded into memory by a program called a loader.
Run the compiled, linked and loaded program with test data. This may show up the existence of
Logical errors in the program. Logical errors are errors that are caused by errors in the method
of solution, thus while the incorrect statement is syntactically correct it is asking the computer
to do something which is incorrect in the context of the application. It may be something as
simple as subtracting two numbers instead of adding them. A particular form of logical error
that may occur is a run-time error. A run-time error will cause the program to halt during
execution because it cannot carry out an instruction. Typical situations which lead to run-time
errors are attempting to divide by a quantity which has the value zero or attempting to access
data from a non-existent file.
The program must now be re-checked and when the error is found it is corrected using the
Editor as in (3) and steps (4) and (5) are repeated until the results are satisfactory.
The program can now be put into general use - though unless the testing was very
comprehensive it is possible that at some future date more logical errors may become apparent.
It is at this stage that good documentation produced while designing the program and writing
the program will be most valuable, especially if there has been a considerable time lapse since
the program was written.
Reference:
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 39 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


[1] https://www.macs.hw.ac.uk/~pjbk/pathways/cpp1/node28.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 40 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary Text for Students


The Computer Revolution/Programming/Five Steps of Programming
< The Computer Revolution
Before going on to discuss the five steps of creating a program it is important to determine what exactly
a program is. A program is a list of instructions that contain data for a computer to follow. Different
programs are written with different languages. An editing program is made with a different
programming "language" than one that uses graphics. Some well known programming languages are
COBOL -business, BASIC -language, and - C which is used in science. Programming is complicated
process, below is general overview of this 5 step procedure.
Contents

1 Clarify Programming Needs


2 Design the Program
o 2.1 Three control structure:
3 Code the Program
4 Test the Program
5 Document and Maintain

Clarify Programming Needs


Knowing the objective is the first consideration. Is it a payroll or editing program? Knowing who the end
user will be is also important. Determining the inputs and outputs is next. How will the program operate
and what data is needed to make it happen. After this has been decided feasibility is the next
consideration. How many programmers will it take, is the project within budget, does the project have
a realistic outline. Finally, if the project is a go, then one must take measures to ensure the project is
properly documented and analyzed.
Four mini steps:

Clarify desired processing


Double - check feasibility of implementing the program
Document the analysis
kopp

Design the Program


Programs use algorithms which are like equations that tell the computer what task to perform. The aim
of the programmer is to create algorithms that are clear and simple. Algorithms are expressed first in
logical hierarchical form known as modularzation. Using modules or (a complete thought) the
programmer creates a logical thought process for the computer to follow. After that the program is
broken down in greater detail using pseudocode. Pseudocode uses terms like if, else, and, then to relate
the programs rules to the computer.
Two mini steps:

Determine program logic through top down approach and modularization, using a
hierarchy chart

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 41 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Design details using pseudocode and/or flowcharts, preferably involving control


structure.

A module, a processing step of a program, made up of logically related program statements.


A hierarchy chart, which represents top-down program design, explains the main purpose of the
program.
Pseudocode, a way of designing a program which uses normal language statements in order to describe
the logic and the processing flow.
Program flowcharts, graphically shows the detailed series of steps

Three control structure:

Sequence control structure - No decision making


Selection control structure Loop control structure/Repetition or Iteration Structure

Code the Program


After the program has been designed it must be coded or written. Using the pseudocode and logic
requirements from step two an appropriate programming language must be selected. As stated in the
introduction, coding languages differ in specifications and usability. Once the appropriate code language
has been chosen, it is imperative that the programmer follow the syntax rules with as little deviation as
possible in order for the program to have high accuraccy.
Two mini steps:

Select the appropriate high-level programming language


Code the program in that language following the syntax carefully

Test the Program


After the program is written it then enters the programming debugging and testing phase of the Program
Development Life Cycle (PDLC). During this time the programmer will be looking for errors in both logic
and syntax, as well as exploring other areas that may cause the program to either not work properly or
to not run at all.
This process is a lengthy and tedious one, oftentimes consisting of up to 50% of a programs time in
development (Morley 523). However, with a careful eye paid to program design and coding the amount
of time spent debugging can be cut considerably.
As stated, debugging will uncover errors in both logic and syntax. Syntax errors will prevent the program
from executing. They can be such simple things as misspelled words or can involve breaking the syntax
rules of the programming language used.
On the other hand, logic errors will allow the program to run but will provide incorrect results. Errors
of this kind may consist of merely using the wrong relational operator or other, larger, mistakes in
writing formulas.
Once the programmer locates the errors they are then fixed and the program is run again. This will
happen multiple times, often called execute, check, and correct (526), until the program runs
flawlessly.
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 42 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


The program will then enter the testing phase.

The Bug hard at work inputting errors.


Reference: Morley, Deborah and Charles S. Parker. Understanding Computers Today and Tomorrow,
13th Edition.

Testing the program comes in two phases, alpha and beta.

Alpha testing is the process of reading through the program in search of errors in logic.

The second step is to run a diagnostic program to search for syntax or input errors.
Beta testing involves using the program in the real world to see if it contains any bugs
or other deficiencies.

Document and Maintain


Documentation should be ongoing from the very beginning because it is needed for those involved with
program now and future. Upon completion User Documentation for commercial use, Operator
Documentation for people who run computer systems, and Programmer Documentation for
programmers charged with maintenance.
Four mini steps:

Write user documentation


Write operator documentation
Write programmer documentation
Maintain the program

Reference:
[1]
https://en.wikibooks.org/wiki/The_Computer_Revolution/Programming/Five_Steps_of_Programming

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 43 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Describe, with examples, the difference between low level and high-level programming
languages used in computers. What do you understand by the term Object Oriented
Programming? 10 October-2007
Difference between Low Level and High-Level Programming Languages:
Learning
Understanding
Execution
Modification

High-level Language
High-level languages are easy to learn.
High-level languages are near to human
languages.
Programs in high-level languages are slow
in execution.
Programs in high-level languages are easy
to modify.

Facility at hardware
level

High-level languages do not provide much


facility at hardware level.

Knowledge of
hardware Deep
Uses

Knowledge of hardware is not required to


write programs.
These languages are normally used to
write application programs.

Low-level languages
Low-level languages are
difficult to learn.
Low-level languages are far
from human languages.
Programs in low-level
languages are fast in execution.
Programs in low-level
languages are difficult to
modify.
Low-level languages provide
facility to write programs at
hardware level.
Deep knowledge of hardware is
required to write programs.
These languages are normally
used to write hardware
programs.

Object Oriented Programming:


Object-oriented programming (OOP) is a programming paradigm based on the concept
of "objects", which are data structures that contain data, in the form of fields, often known as attributes;
and code, in the form of procedures, often known as methods. A distinguishing feature of objects is that
an object's procedures can access and often modify the data fields of the object with which they are
associated (objects have a notion of "this" or "self"). In OO programming, computer programs are
designed by making them out of objects that interact with one another. There is significant diversity in
object-oriented programming, but most popular languages are class-based, meaning that objects are
instances of classes, which typically also determines their type.
Many of the most widely used programming languages are multi-paradigm
programming languages that support object-oriented programming to a greater or lesser degree,
typically in combination with imperative, procedural programming. Significant object-oriented
languages include Common Lisp, Python, C++, Objective-C, Smalltalk, Delphi, Java, Swift, C#, Perl, Ruby,
and PHP.

Reference:
[1] http://iamcomputerexpert.blogspot.com/2008/09/difference-between-low-level-high-level.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 44 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What is a debugger? How does it help a programmer? 5 October-2008
Debugger:
A debugger or debugging tool is a computer program that is used to test and debug other
programs (the "target" program). The code to be examined might alternatively be running on an
instruction set simulator (ISS), a technique that allows great power in its ability to halt when specific
conditions are encountered. but which will typically be somewhat slower than executing the code
directly on the appropriate (or the same) processor. Some debuggers offer two modes of operation
full or partial simulationto limit this impact.
A "trap" occurs when the program cannot normally continue because of a programming bug or invalid
data. For example, the program might have tried to use an instruction not available on the current
version of the CPU or attempted to access unavailable or protected memory. When the program "traps"
or reaches a preset condition, the debugger typically shows the location in the original code if it is a
source-level debugger or symbolic debugger, commonly now seen in integrated development
environments. If it is a low-level debugger or a machine-language debugger it shows the line in the
disassembly (unless it also has online access to the original source code and can display the appropriate
section of code from the assembly or compilation).

How it helps a Programmer:


In computers, debugging is the process of locating and fixing or bypassing bugs (errors) in computer
program code or the engineering of a hardware device. To debug a program or hardware device is to
start with a problem, isolate the source of the problem, and then fix it. A user of a program that does not
know how to fix the problem may learn enough about the problem to be able to avoid it until it is
permanently fixed. When someone says they've debugged a program or "worked the bugs out" of a
program, they imply that they fixed it so that the bugs no longer exist.
Debugging is a necessary process in almost any new software or hardware development process,
whether a commercial product or an enterprise or personal application program. For complex products,
debugging is done as the result of the unit test for the smallest unit of a system, again at component test
when parts are brought together, again at system test when the product is used with other existing
products, and again during customer beta test, when users try the product out in a real world situation.
Because most computer programs and many programmed hardware devices contain thousands of lines
of code, almost any new product is likely to contain a few bugs. Invariably, the bugs in the functions that
get most use are found and fixed first. An early version of a program that has lots of bugs is referred to
as "buggy."
Debugging tools (called debuggers) help identify coding errors at various development stages. Some
programming language packages include a facility for checking the code for errors as it is being written.

Reference:
[1] http://searchsoftwarequality.techtarget.com/definition/debugging

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 45 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What are program comments? Why are they needed? 5 October-2008
Program Comments:
In computer programming, a comment is a programmer-readable annotation in the
source code of a computer program. They are added with the purpose of making the source code easier to
understand, and are generally ignored by compilers and interpreters. The syntax of comments in various
programming languages varies considerably.
As well as of direct use to any programmer reading the source code, comments are
sometimes processed in various ways to generate documentation external to the source code itself by
documentation generators, or used for integration with source code management systems and other
kinds of external programming tools.
The flexibility provided by comments allows for a wide degree of variability, but
formal conventions for their use are commonly part of programming style guides.
Why they are needed:
Comments Are More Important Than Code
The thorough use of internal documentation is one of the most-overlooked ways of improving software
quality and speeding implementation.
Programs are meant to be beautiful. If someone tells you otherwise, you'd probably do best not to listen
to the rest of his advice. A good program is beautiful in both its concept -- the algorithm used, the design,
the flow of control -- but also in its readability. Good code is not replete with question mark colon
operators and pointer arithmetic, or at least not when the code doesn't need to be optimized to save a
few seconds every few months of operation. But readable code, while a nice ideal, often requires some
help from the English (or from some other) language. Sometimes the algorithm is too complex to be
understood rapidly or completely without some explanation, or the code requires some esoteric
function call from the C library that has both a cryptic and a misleading name. And if you ever plan to
code for a living, you will almost certainly have to go back several years later to modify the one section
of code that you didn't feel like commenting -- or someone else will, and will curse your name. Finally,
commenting code can also lead to a better understanding of the program and may help uncover bugs
before testing. For both aesthetic and practical reasons, good commenting is an essential and often
overlooked programming skill.
Reference:
[1] https://en.wikipedia.org/wiki/Comment_%28computer_programming%29

[2] http://queue.acm.org/detail.cfm?id=1053354
[3] http://www.cprogramming.com/tutorial/comments.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 46 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What are the four steps that should be taken before writing a Computer Program?
Four Steps to Take before Writing a Computer Program
Before you start writing a computer program, first take four critical steps to design it. By doing so, you
don't waste time writing a computer program that doesn't work or that solves the wrong problem and
isn't worth trying to salvage afterward. With planning, you increase the odds that your computer
program actually works and performs the task that you want.
The following four steps are crucial to take when designing any program:

1. Identify the problem: What problem does your program solve? If you can't clearly state
what your program does, you won't know how to design it.
2. Identify the user: Who's going to use your program?
3. Determine the target computer: Which computer do people need to run your program?
Is it a Windows computer, a Macintosh, a mainframe, a computer running Linux, a
handheld Palm or Pocket PC, or a supercomputer?
4. Determine your programming skill: Are you going to write the entire thing yourself or
get help from others? If you're going to get others to help you, which parts of the
program are they going to write?
Computer programming: Identify the problem
Every program solves a problem. A tax return program solves the problem of organizing and filing your
taxes. A word processor solves the problem of writing, editing, formatting, and printing text. Even a
video game solves the problem of keeping people amused.
A program is only as useful as the problem it solves. Most programs simplify and automate an existing
problem, such as a money management program that simplifies organizing and paying bills instead of
using paper and an adding machine. The goal of any program is to make a specific task faster, easier, and
more convenient. The only way reach that goal is to identify what task your program is trying to solve
in the first place.
Identify the computer program's users
If you're the only person who's going to use your program, you can pretty much make your program
look and act any way you want, just as long as you know how to make it work. But if you plan to give or
sell your program to others, you need to know who's going to use it.
Knowing your program's typical user is critical. If users don't like your program for any reason, they're
unlikely to use it. Whether the program actually works is often irrelevant.
By designing your program with the user in mind, you increase the odds that people use your program
and (you hope) buy a copy for themselves.
Even if you write a program that works perfectly, users still may ignore it because they don't like the
way it looks, they don't understand how to give it commands, it doesn't work the same way as the old
program they currently use, the colors don't look right to them, and so on. The goal is to make your
program meet your users' needs, no matter how weird, bizarre, or illogical they may seem (the needs
not the users).
Determine the target computer for your computer program

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 47 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


After you identify the user, you need to know what type of computer the user intends to run the program
on. The type of computer that your program runs on can determine which computer languages you can
use, the hardware that your program can expect to find, and even the maximum size of your program.
If you're writing a program to run on a Macintosh, for example, your program can take advantage of
sound, color graphics, a large hard drive, and plenty of memory. You may need to rewrite that same
program drastically, however, to run it on a smart phone with its limited sound capability, much simpler
color graphics, and limited amount of memory and storage space.
If you can copy and run your program on another computer with little or no modification, your program
is considered portable. The computer language that you use to write your program can determine its
portability. That's why so many people use C/C++ C and C++ programs tend to be more portable
than other programming languages.
Determine your programming skill
When designing any program, consider your programming skill. You may get a great idea for a program,
but if you're a beginner with little experience, writing your program may take a long time if you don't
give up out of frustration first.
Your programming skill and experience also determine the programming language that you choose.
Experienced programmers may think nothing about writing entire programs in C or C++. But novices
may need to spend a long time studying C and C++ before writing their programs, or they may choose
an easier programming language, such as BASIC.
Some novices take the time to learn difficult languages, such as C/C++, and then go off and write their
program. Others take an easier approach and choose a simpler language such as Visual Basic so they can
create (and market) their programs right away. Don't be afraid to tackle a heavy-duty language such as
C/C++, but don't be afraid to use a simpler language such as Visual Basic either. The important goal is
to finish your program so you can start using it and (possibly) start selling it to others.
Many programmers create their programs by using a language such as Visual Basic and then later hire
more experienced programmers to rewrite their programs in a more complex language such as C/C++,
which can make the program faster and more efficient.

Reference:
[1]
http://www.dummies.com/how-to/content/four-steps-to-take-before-writing-computerprogram.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 48 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What is a High Level Language? What features are necessary in a high level language?
5 October-2010
High Level Language:
In computer science, a high-level programming language is a programming language with
strong abstraction from the details of the computer. In comparison to low-level programming languages,
it may use natural language elements, be easier to use, or may automate (or even hide entirely)
significant areas of computing systems (e.g. memory management), making the process of developing a
program simpler and more understandable relative to a lower-level language. The amount of
abstraction provided defines how "high-level" a programming language is.

Characteristic of High Level Language:-

High level languages have several features:


Abstraction
Data Abstraction: The machine's representation of information is hidden.
Computation Abstraction: Machine instructions are hidden by higher-level
operations and procedural abstraction
Precise representation
Algorithms expressed in a form suited for computer processing. Syntax** and Semantics must
be obeyed.
Translation
Compiled: Program text is converted to executable code, which is then executed
Interpreted: Program text is analyzed and executed one step at a time

Easy to learn:-

The high Level Languages are close to human languages. The instructions written in
high level languages are similar to English like words and Statements. This makes the high level
languages easy to learn and use.

Easy to detect errors:-

The logic of the program written in high level languages is very simple and easy. The
instructions of program are like English language statements. In case of errors, it is very easy
to detect (or find) and remove errors in the Program. It is also easy to modify the Program.

Machine Independent:-

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 49 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


The program written in High Level Language is machine independent. It means that
a program written or compiled on one type of Computer can be executed (run) on another
different type of Computer that has different architecture.

For Example:-

A program written on a Computer using Intel Processor can be run on computer


having Motorola Processor (but with a little Modification).

Availability of Liberty Functions:-

Every High Level Language provides a large number of Built in functions (or library
functions) that can be used to perform specific tasks during designing of new Programs.

For Example:

To computer the square root of a number, the programmer can use the available built
in function without writing its own code. This way of writing a program reduces the
development time of a program. This software is developed in a very short time.

Shorter Program:-

The Program written in high level language is shorter than the program written in
low level language. A single instruction of the program written in High Level Language may be
equivalent to many instructions of low level programming language.

Well defined Syntax and standard:-

Every high level language has a standard syntax. The standard is approved (or
established) by international organization. The most popular organization is ANSI (American
National Standard Institute). The translator programs are written according to the standard
syntax of the language. Therefore, high level languages describe a well defined way of writing
programs.

Source code is understandable by another programmer:-

The instructions of the program written in high level language are like English
language statements. These are written according to the standard syntax of the language.
Therefore, a computer programmer can easily understand a program written by another
programmer.
Reference:
[1]
http://cprogramming007.blogspot.com/2012/01/characteristics-of-high-levellanguages.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 50 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What is High Level Programming Languages? Name ten popular high level
programming languages. Briefly describe about them. 10 April-2004
High Level Programming Languages:
In computer science, a high-level programming language is a programming language with
strong abstraction from the details of the computer. In comparison to low-level programming languages,
it may use natural language elements, be easier to use, or may automate (or even hide entirely)
significant areas of computing systems (e.g. memory management), making the process of developing a
program simpler and more understandable relative to a lower-level language. The amount of
abstraction provided defines how "high-level" a programming language is.
Following are some popular high level programming Languages:
11. Java
12. C
13. C#
14. C++
15. Objective-C
16. PHP
17. Visual Basic
18. Python
19. Perl
20. JavaScript

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 51 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary Text for Students


1. Java
What is it?
An object-oriented programming language developed in the late 1990s by James Gosling and
colleagues at Sun Microsystems.
Why is it important?
This beautiful programming language is central for any non-Microsoft developer, i.e. any
developer who focuses on the non-.NET experience. It is mostly derived from C and C++ but
has a more basic object model. It ranked first on TIOBEs list of most popular programming
languages.

2. C

What is it?
C, a general purpose programming language built by Dennis Ritchie when he was a part of Bell
Telephone labs, is the bass of C++ and other programming languages. It was built to work with
the Unix operating system.
Why is it important?
C is one of the most widely used programming languages of all time, and ranked second on the
list. Learning C is crucial. Once you learn C, making the jump to Java or C# is fairly easy, because
a lot of the syntax is common. Also, a lot of C syntax is used in scripting languages, Wayne
Duqaine, director of Software Development at Grandview Systems, of Sebastopol, Calif., told
eWEEK.

3. C#
What is it?
This general-purpose programming language developed by Microsoft evolved from C and C++
as
a
part
of
the
software
companys
.NET
initiative.
Why is it important?
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 52 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


This language is an essential part of the .NET framework, so developers who use Microsoft
heavily will find it critical, according to Duqaine.
4. C++

What is it?
C++ is a general purpose multi-paradigm spanning compiled language that has both high-level
and low-level languages features. It was started as an enhancement to the C programming
language, Bjarne Stroustrup in 1979.
Why is it important?
It is one of the most popular programming languages, winning fourth place on the list, with
application domains including systems software, application software, server and client
applications, and entertainment software such as video games. The language has also greatly
influenced many other popular programming languages, such as C# and Java.
5. Objective-C

What is it?
This object-oriented programming language created first by Brad Cox and Tom Love at their
company Stepstone in the early 1980s, adds Smalltalk-like messaging to the C programming
language.
Why is it important?
This language is most used on the Apple iOS and Mac OS X. Objective-C is the principal language
used for Apple's Cocoa API as well.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 53 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

6. PHP
What is it?
This language is especially suited for Web development because of it easy embedding into
HTML pages. It is an open-source, server-side, cross-platform, interpretive HTML scripting
language
Why is it important?
It is a popular language, ranking sixth on TIOBEs list. "High-speed scripting with caching,
augmented with compiled code plug-ins (such as can be done with Perl and PHP) is where the
future is. Building Web apps from scratch using C or COBOL is going the way of the dinosaur,"
said
Duquaine,
according
to
eWEEKs
report.
7. (Visual) Basic
What is it?
This is an event-driven programming language which is implemented on Microsofts .Net
framework.
Why is it important?
This language ranked as the seventh most popular language on TIOBEs list, probably because
it was designed by Microsoft to be easy to learn and use. According to Tim Huckaby, CEO of San
Diego-based software engineering company CEO Interknowlogy.com, It is currently
dominating in adoption and that is where all the work is, as in eWEEKs report.

8. Python
What is it?
This is an event-driven programming language which is extensively used by Google because of
its simplicity. It is managed by the Python Software Foundation.

Why is it important?
Python is a general-purpose, high-level programming language whose design philosophy
emphasizes code readability. Python claims to combine "remarkable power with very clear
syntax", and its standard library is large and comprehensive.
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 54 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

It is releases on 4 September 2011, 6 months ago.It is developed by Python Software


Foundation.
9. Perl
What is it?
Being a high-level programming language, its emphasis lies in code readability and clear syntax.
It combines Object-oriented and functional programming styles, and is often used as a scripting
language. Perl is an open-source language used widely to process text through CGI programs.

Why is it important?
Perls efficiency in processing of piles of text has ranked it ninth in terms of programming
language popularity. It is used extensively to write Web server programs for a variety of tasks.
Learning some form of scripting language, such as Perl or PHP is critical if you are doing Web
apps," told Wayne Duqaine, director of Software Development at Grandview Systems, of
Sebastopol,
Calif.,
in
a
talk
with
eWEEK.
10. JavaScript
What is it?
JavaScript is an object-oriented scripting language that is smaller than Java. Being a client-side
language, it runs in the web browser on the client-side with a simplified set of commands, easier
code
and
no
need
for
compilation.

Why is it important?
JavaScript is simple to learn and is the tenth most widely used programming language. It is used
in millions of web pages to authenticate forms, detect browsers and improve design, and it is
easier to run these functions as it is embedded into HTML.
Reference:
[1] http://www.freerepublic.com/focus/chat/2880277/posts

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 55 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What are some of the best programming languages to learn?
This is a question that is asked by beginners, as well as experts. As with many important questions, the
answer is not simple. There are many factors that should be taken into account while deciding a
programming language to learn.
Technology evolves in matter of weeks and by the time you become expert in a particular software
technology, it can already be considered obsolete. Another extremely important thing to note is that
programming languages vary greatly in terms of functionality and complexity. The answer to what
programming language you should learn majorly depends upon the type of task you want to perform.
For instance, if you are developing some static web-based application, you might need to learn simple
HTML. Conversely, if you want to develop a more dynamic application with advanced capabilities, you
might need to learn ASP.NET, PHP, Ruby on Rails, or Javascript and and accompanying framework.
Desktop and mobile applications have different requirements as well.
In addition to that, another interesting aspect of programming that I noticed is that not only
programmers and software engineers are interested in learning new programming languages, but
people from totally different walks of life are also into it. Recently, I came across a PhD researcher with
psychology as a research area. He was instructed by his supervisor to learn some advanced
programming language because he would be required to display his research result in form of a software
application. He was also asking the same question about what from where he should start. That shows
that programming is not limited to programmers, with rigorous practice and attention, anyone, yes
anyone, can program.
Now back to the top 10. I have decided to compile a list of programming languages that can be helpful
in deciding which to pursue, and have also added a number of typical developer types or tracks that
you could become or experiment with. You should have a look at these languages and decide which is
best suited for your requirements. So, lets get started.

1. C Language

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 56 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


I vividly remember that the first programming language course that I had in my university was of C
language. Our instructor assigned us a task to add two numbers using C. And when we completed the
task, we felt like the best programmers on earth. C is definitely a very good programming language to
learn, specifically for the beginners who are intending for a programming career in the long run.
A bit of history: C language was developed by Dennis Ritchie in 1972, at Bell labs. The legacy of C
language stems from the fact that it is ancestor to many of the advanced programming languages such
as C++, Java, C#, JavaScript, and Pearl. It is probably due to this reason that C is the first programming
course offered in universities as it paves way for learning other languages. C language is mostly used for
developing low level applications as it is considered nearest to the hardware amongst all languages,
baring assembly language. If youre a beginner, here is a great starter course to C.
2. C++ Language
Though C language was performing extremely well, it lacked object orientation. In order to address this
issue, C++ language was developed in 1983 which is often considered object oriented version of C
language. C++ is one of the most widely used languages of the world with many amazing applications
developed through it. Google Chrome, Mozilla Firefox, Winamp, and the complete suite of Adobe
Software were developed using C++. Apart from that, several advanced games and operating systems
like windows have been developed in C++ due to its quick processing and compilation mechanism.
Also, C++ developers are in extremely high demand in the job market and the number of vacancies is
growing. You can visit Udemy C++ to learn how to program in this rapidly growing language.

3. Java
Java was developed by James Gosling, in 1990 at Sun Microsystems. Java further adds to the capabilities
of C++ language. It is often said that Java owes a lot to C and C++ in terms of features and capabilities.
The special thing about Java is that this is the first purely object oriented programming language. Java
was developed on the principle of WORA i.e. Write Once Run Anywhere. This feature adds to the
portability of Java. You just need to compile Java Source code once and then on any machine where JVM
(Java Virtual Machine is installed), you can run that code irrespective of the underlying operating system
and hardware.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 57 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Java language is used to develop enterprise level application and video games; it can be employed to
develop web based applications when used with JSP (Java Server Pages). Java has huge job market with
attractive incentives. This is a must learn language for every programmer. The ultimate guide to Java for
beginners can help you master this language.
4. C#
C# belongs to the Microsofts family of programming language and was developed in 2000 to be the part
of the first ever release of Microsofts prestigious .NET framework. C# is very similar to Java in terms of
capabilities. It has been said that C# combines the robustness of C++ with the advanced features of Java.
Therefore, if you are good at Java, it is extremely easy to switch to C# and vice-versa.
C# language is used to develop almost all types of software applications that come with Visual Studio
IDE. If you are developing a dynamic web based application in ASP.NET, you will be required to code in
C# or VB to write backend handling mechanism. If you are developing a Windows form application or a
Windows Presentation Foundation (WPF) Application, you will be required to code in C#. Similarly, if
you are developing a windows phone application, again you will be required to code in C#.
Keeping in view, the importance of the usage of C# in Microsofts application, you should definitely
consider it if you are looking to develop applications for Windows-based platforms. The job market for
C# programmers is also good and you can find a lucrative job being a C# programmer. Explore the
fundamentals of C# in this course.
5. Objective C
Objective-C was initially developed at Apple by Brad Cox and Tom Love, in 1983. The purpose of
developing Objective-C programming language was to address the deficiencies in C language. The major
shortcoming in C language was object orientation which provoked many developers to devise languages
that incorporate object orientation paradigm. As a result C++ and Object-C were developed. However,
the latter have gained immense popularity owing to its use in developing applications for Apples iPhone
and iPad.
Sound knowledge of Objective-C would be helpful in landing you a job in companies that develop Apple
based software applications. In addition to that, freelance industry also has huge demand for ObjectiveC coders across the globe. Just getting started? Learn coding alongside a professor in this course for
beginners.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 58 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

6. PHP
PHP (Hypertext Preprocessor) is one of the most widely used languages used to develop dynamic
websites. PHP was developed in 1995 and is a server-side scripting language which means that PHP
code is processed on the server and end result is sent to the user of the website in the form of plain
HTML.
PHP is an open-source language which means that there are thousands of already built modules that can
be modified to achieve the desired functionality. Also, PHP is easy to learn; you simply have to embed
the code inside HTML. And if there was anything left, there are hundreds of PHP platforms available
such as Joomla, WordPress, and Drupal that allow you to develop websites even more conveniently. PHP
is one language that every programmer should learn if he or she plans to pursue a web developers
career. PHP is also an integral part of the famous LAMP (Linux Apache MySQL and PHP) platform that
Facebook, Yahoo, and other famous websites use. PHP has a huge job market, though not much highly
paid when compared to ASP.NET developers; PHP developers easily find decent jobs. Some easy and
comprehensive tutorials are available at Udemy PHP.
7. JavaScript
Server side languages are ideal for developing complex web applications but performing every task on
server puts lots of load on a server. For this reason, developers often delegate some part of the
functionality to client side and for this purpose JavaScript is used. JavaScript is a client side
programming language that runs inside a client browser and process commands on client computer
rather than server which results in decreased load on server and increased applications execution
speed. JavaScript has been designed by Netscape and there is hardly any website that doesnt make use
of JavaScript. Though, JavaScript alone will not help you land a job but if you are looking to pursue a
career in web development, JavaScript is a must learn language along with some advanced server side
scripting language. A good resource to learn Java is available at Udemy.com. Join over a thousand
students who have taken this course on comprehensive JavaScript programming.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 59 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

8. Python
Python is another high-level programming language and is often considered on the easiest language to
learn, owing to its simplicity, readability and straight forward syntax. Python was developed by Guido
Van Rossum in 1991. Python wasnt used that widely in the past; however, the language has seen great
surge in popularity in the recent years owing to Googles investment in the language in the past 10 years
or so. Currently, some highly famous and robust sites are operating in python including pinterest.com,
instagram.com, and rdio.com. Like, PHP, Python also has associated web frameworks which make it
more convenient to develop web based applications in python. Django is one such platform which
powers the sites aforementioned. There are two renowned courses on Python for beginners that Id like
to recommend: this course on Python programming and this Ultimate Python Tutorial.
9. SQL
SQL is not a development language; it is actually a database query language. SQL stands for Structured
Query Language. SQL provides a standardized way of interacting with the underlying database of an
application. SQL is extremely simple to learn and is probably closest to the English language in terms of
syntax. Almost every application has a backend database and in order to interact with that you will need
to have sound knowledge of SQL. Like JavaScript, SQL alone is not that beneficial in terms of job
placement; however, good command of SQL can help you stand out of crowd. Therefore, it is highly
recommended that you learn it. You can try out this beginners SQL crash course to start!
10. Ruby
Similar to Python, Ruby is also a simple and readable programming language mainly focused on
developing web-based applications. Designed by Yukihiro Matsumoto in 1995, Ruby powers Ruby on
Rails, a web development framework on which numerous renowned websites including Github, Scribd,
Yammer, Shopify, and Groupon have been developed. Ruby is regarded as combination of some of the
most famous features of Lisp, Pearl and Eiffel. Ruby also has got a good job market and ruby developers
are being paid decently at the moment. Learn Ruby quickly and painlessly with this course!

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 60 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


And nowthe rankings! For your convenience, I have compiled some facts about these languages based
on their job scope and general rank along with current number of vacancies available at famous job sites.
These stats will help you choose what languages to learn.

Languages

TIOBE

1
4
2
6
3

JobsTractor
Vacancies
Rank
at
Indeed.com
13
8112
10
31199
1
67753
8
31935
3
4473

5
8
11

2
9
5

Rank
C
C++
Java
C#
ObjectiveC
PHP
Python
Ruby

19953
24916
13621

Which Language to choose from the above?

I have explained ten of the most famous and usable programming languages that
one should learn, but the question still lingers that which language is the best. Unfortunately, only you
can answer this question. Apart from considering the stats that I mentioned in the last section, following
are some of the factors that you should take into account while selecting a particular language for
development.

What the requirements of the application you want to develop are; web-based, desktop
or mobile application?
What your personal interests are; commercial or open source technologies?
What the job market of the language is.
Learning curve for a particular language.

Though these are some general guidelines, in the current market where job competition is at its peak,
you must be proficient in at least one web-based language, one desktop based programming language,
and at least one mobile platform, in order to distinguish yourself among contemporary programmers.

Reference:
[1] https://blog.udemy.com/best-programming-language/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 61 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Flowcharts
Question: What is Flowchart? What are the advantages and limitations of Flowcharts?
Flowcharts:
A flowchart is a graphical representation of the sequence of operations in an information
system or program. Program flowcharts show the sequence of instructions in a single program or
subroutine.
Flowchart uses boxes of different shapes to denote different types of instructions. The actual
instructions are written within these boxes using clear and concise statements. These boxes are
connected by solid lines having arrow marks to indicate the flow of operation, that is, the exact sequence
in which the instructions are to be executed. Since a flowchart shows the flow of operations in pictorial
form, any error in the logic of the procedure can be detected easily. Once the flowchart is ready, the
programmer can forget about the logic and can concentrate only on coding the operations in each box
of the flowchart in terms of the statements of the programming language. This will normally ensure an
error-free program.
Advantages of Flowcharts
Conveys Better Meaning
Since a flowchart is a pictorial representation of a program, it is easier for a programmer to understand
and explain the logic of the program to some other programmer.
Analyses the Problem Effectively
A macro flowchart that charts the main line of logic of a software system becomes a system model that
can be broken down into detailed parts for study and further analysis of the system.
Effective Joining of a Part of a System
A group of programmers are normally associated with the design of large software systems. Each
programmer is responsible for designing only a part of the entire system. So initially, if each
programmer draws a flowchart for his part of design, the flowcharts of all the programmers can be
placed together to visualize the overall system design. Any problem in linking the various parts of the
system can be easily detected at this stage and the design can be accordingly modified. Flowcharts can
thus be used as working models in the design of new programs and software systems.
Efficient Coding
Once a flowchart is ready, programmers find it very easy to write the concerned program because the
flowchart acts as a roadmap for them. It guides them in proceeding from the starting point of the
program to the final point ensuring that no steps are omitted. The ultimate result is an error free
program developed at a faster rate.
Systematic Debugging
Even after taking full care in program design, some errors may remain in the program because the
designer might have never thought about a particular case. These errors are detected only when we
start executing the program on a computer. Such type of program errors are called bugs and the process
of removing these errors is known as debugging. A flowchart is very helpful in detecting, locating, and
removing mistakes (bugs) in a program in a systematic manner.
Systematic Testing
Testing is the process of confirming whether a program will successfully do all the jobs for which it has
been designed under the specified constraints. For testing a program, different sets of data are fed as
input to that program to test the different paths in the program logic.
Limitations of Flowcharts
Takes More Time to Draw
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 62 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Flowcharts are very time consuming and laborious to draw with proper symbols and spacing, especially
for large complex programs.
Difficult to Make Changes
Owing to the symbol-string nature of flowcharting, any changes or modifications in the program logic
will usually require a completely new flowchart. Redrawing a flowchart is tedious and many companies
either do not change them or produce the flowchart by using a computer program to draw it.
Non-standardization
There are no standards determining the amount of detail that should be included in a flowchart.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 63 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary text for Students


Advantages of Using Flowcharts:
The benefits of flowcharts are as follows:
_ Communication: Flowcharts are better way of communicating the logic of a system to all concerned.
_ Effective analysis: With the help of flowchart, problem can be analysed in more effective way.
_ Proper documentation: Program flowcharts serve as a good program documentation, which is needed
for various purposes.
_ Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program
development phase.
_ Proper Debugging: The flowchart helps in debugging process.
_ Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of
flowchart. It helps the programmer to put efforts more efficiently on that part.
Limitations of Using Flowcharts:
Although a flowchart is a very useful tool, there are a few limitations in using flowcharts which are listed
below:
_ Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart becomes
complex and clumsy.
_ Alterations and Modifications: If alterations are required the flowchart may require re-drawing
completely.
_ Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a
problem.
_ The essentials of what is done can easily be lost in the technical details of how it is done.
When to Use a Flowchart:
_ To communicate to others how a process is done.
_ A flowchart is generally used when a new project begins in order to plan for the project.
_ A flowchart helps to clarify how things are currently working and how they could be improved. It also
assists in finding the key elements of a process, while drawing clear lines between where one process
ends and the next one starts.
_ Developing a flowchart stimulates communication among participants and establishes a common
understanding about the process. Flowcharts also uncover steps that are redundant or misplaced.
_ Flowcharts are used to help team members, to identify who provides inputs or resources to whom, to
establish important areas for monitoring or data collection, to identify areas for improvement or
increased efficiency, and to generate hypotheses about causes.
_ It is recommended that flowcharts be created through group discussion, as individuals rarely know
the entire process and the communication contributes to improvement.
_ Flowcharts are very useful for documenting a process (simple or complex) as it eases the
understanding of the process.
_ Flowcharts are also very useful to communicate to others how a process is performed and enables
understanding of the logic of a process.
Reference:
[1] http://archive.mu.ac.in/myweb_test/syllFybscit/C++.pdf

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 64 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What is an algorithm? What is a flowchart? 4 April-2011
Algorithm:
A computer is a useful tool for solving a great variety of problems. To make a computer do
anything (i.e. solve a problem), you have to write a computer program. In a computer program you tell
a computer, step by step, exactly what you want it to do. The computer then executes the program,
following each step mechanically, to accomplish the end goal.
The sequence of steps to be performed in order to solve a problem by the computer is known as
an algorithm.
In mathematics, computer science, and related subjects, an algorithm is a finite sequence of steps
expressed for solving a problem. An algorithm can be defined as a process that performs some sequence
of operations in order to solve a given problem. Algorithms are used for calculation, data processing,
and many other fields.
Flowchart:
Flowchart is a graphical or symbolic representation of an algorithm. It is the diagrammatic
representation of the step-by-step solution to a given problem.
A Flowchart is a type of diagram (graphical or symbolic) that represents an algorithm or
process. Each step in the process is represented by a different symbol and contains a short description
of the process step. The flow chart symbols are linked together with arrows showing the process flow
direction. A flowchart typically shows the flow of data in a process, detailing the operations/steps in a
pictorial format which is easier to understand than reading it in a textual format.
A flowchart describes what operations (and in what sequence) are required to solve a given
problem. A flowchart can be likened to the blueprint of a building. As we know a designer draws a
blueprint before starting construction on a building. Similarly, a programmer prefers to draw a
flowchart prior to writing a computer program.
Flowcharts are a pictorial or graphical representation of a process. The purpose of all flow
charts is to communicate how a process works or should work without any technical or group specific
jargon. Flowcharts are used in analyzing, designing, documenting or managing a process or program in
various fields.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 65 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write the Advantages and Limitations Of Machine Language And Assembly
Language.10 April-2009
Machine Language:
Machine Language is the only language that is directly understood by the computer. It does not needs
any translator program. We also call it machine code and it is written as strings of 1's (one) and 0s
(zero). When this sequence of codes is fed to the computer, it recognizes the codes and converts it in to
electrical signals needed to run it. For example, a program instruction may look like this:
1011000111101
It is not an easy language for you to learn because of its difficult to understand. It is efficient for the
computer but very inefficient for programmers. It is considered to the first generation language. It is
also difficult to debug the program written in this language.
Advantage Machine Language:
The only advantage is that program of machine language run very fast because no translation program
is required for the CPU.
Disadvantages Machine Language:
1. It is very difficult to program in machine language. The programmer has to know details of hardware
to write program.
2. The programmer has to remember a lot of codes to write a program which results in program errors.
3. It is difficult to debug the program.
Assembly Language:
It is the first step to improve the programming structure. You should know that computer can handle
numbers and letter. Therefore some combination of letters can be used to substitute for number of
machine codes.
The set of symbols and letters forms the Assembly Language and a translator program is required to
translate the Assembly Language to machine language. This translator program is called `Assembler'. It
is considered to be a second-generation language.
Advantages Assembly Language:
1. The symbolic programming of Assembly Language is easier to understand and saves a lot of time and
effort of the programmer.
2. It is easier to correct errors and modify program instructions.
3. Assembly Language has the same efficiency of execution as the machine level language. Because this
is one-to-one translator between assembly language program and its corresponding machine language
program.
Disadvantages Assembly Language:
1. One of the major disadvantages is that assembly language is machine dependent. A program written
for one computer might not run in other computers with different hardware configuration.

Reference:
[1] http://successnotes4u.blogspot.com/2012/02/machine-language-its-advantages.html
[2] http://successnotes4u.blogspot.com/2012/02/assembly-language-its-advantages-and.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 66 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Briefly discuss about the advantages of High-level Language. 5 Marks
Advantages of High-Level Languages
High-level languages such as C and Java are preferred because they provide a convenient abstraction of
the underlying system suitable for problem solving. The advantages of programming in a high-level
language rather than in an assembly language include the following:
1. Program development is faster in a high-level language.
Many high-level languages provide structures (sequential, selection, iterative) that facilitate program
development. Programs written in a high-level language are relatively small and easier to code and
debug.
2. Programs written in a high-level language are easier to maintain.
Programming for a new application can take several weeks to several months, and the lifecycle of such
an application software can be several years. Therefore, it is critical that software development be done
with a view toward software maintainability, which involves activities ranging from fixing bugs to
generating the next version of the software. Programs written in a high-level language are easier to
understand and, when good programming practices are followed, easier to maintain. Assembly language
programs tend to be lengthy and take more time to code and debug. As a result, they are also difficult to
maintain.
3. Programs written in a high-level language are portable.
High-level language programs contain very few machine-specific details, and they can be used with little
or no modification on different computer systems. In contrast, assembly language programs are written
for a particular system and cannot be used on a different system.
4. High-level instructions:
Program development is faster
Fewer lines of code
Program maintenance is easier
5. Compiler translates to the target machine language.
Reference:
[1] http://repository.uobabylon.edu.iq/2010_2011/3_21649_37.doc
[2] http://www.c-jump.com/CIS77/ASM/Assembly/A77_0010_high_level.htm

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 67 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Compare While and for Loops that are used in a programming language. List the names and
symbols of the logical and relational operators that are used in C/C++. 6 October-2013
Comparison between While and For Loops:
Basically, there are two major differences between these two loops.
1. In for loop, initialization, condition and adjustment statements are all put together in one line which
make loop easier to understand and implement. While in the while loop, initialization is done prior to the
beginning of the loop. Conditional statement is always put at the start of the loop. While adjustment can
be either combined with condition or embedded into the body of the loop. For example:
/*
* for loop
*/
for (initialization; condition; adjustment) {
}
/*
* while loop
*/
initialization;
while (condition) {
statements;
adjustment;
}
Example:
#include <stdio.h>
int main(void)
{
int count;
count = 0;
/*
* adjustment is put together with condition
*/
while (count < 10 && (count += 1))
printf("count is %d\n", count);
return 0;
}
2. When using continue; statement in for loop, control transfers to adjustment statement while in while
loop control transfers to the condition statement. For example:
for (initialization; condition; adjustment) {
statements;
continue;
- - - -;
statements;
}
initialization;
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 68 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


while (condition) {
statements;
continue;
adjustment;
}
Examples:
int main(void)
{
int count;
count = 0;
/*
* 1. adjustment is with the condition
* 2. continue; statement transfers control to the
* "condition + adjustment" in the first line
* 3. continue; statement like break; statement should
* be put under decision-control statements
* 4. observe the output of the program
*/
while (count < 10 && (count += 1)) {
if (count <= 5)
continue;
printf("count is %d\n", count);
}
return 0;
}
int main(void)
{
int count;
/*
* 1. adjustment is embedded into the body of the loop
* 2. continue; statement transfers control to the "condition and not
* to the adjustment" in the first line
* 3. continue; statement like break; statement should be put under
* decision-control statements
* 4. observe the output of the program, how it differs from the previous example
*/
count = 0;
while (count < 10)) {
count += 1;
if (count <= 5)
continue;
printf("count is %d\n", count);
}
return 0;
}
Names and Symbols Of The Logical And Relational Operators:
Relational Operators
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 69 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


The following table shows all the relational operators supported by C. Assume variable A holds 10 and
variable B holds 20 then
Operator
==
!=

>

<

>=

<=

Description
Checks if the values of two operands are equal or
not. If yes, then the condition becomes true.
Checks if the values of two operands are equal or
not. If the values are not equal, then the condition
becomes true.
Checks if the value of left operand is greater than the
value of right operand. If yes, then the condition
becomes true.
Checks if the value of left operand is less than the
value of right operand. If yes, then the condition
becomes true.
Checks if the value of left operand is greater than or
equal to the value of right operand. If yes, then the
condition becomes true.
Checks if the value of left operand is less than or
equal to the value of right operand. If yes, then the
condition becomes true.

Example
(A == B) is not true.
(A != B) is true.

(A > B) is not true.

(A < B) is true.

(A >= B) is not true.

(A <= B) is true.

Logical Operators
Following table shows all the logical operators supported by C language. Assume variable A holds 1
and variable B holds 0, then
Operator
&&
||

Description
Called Logical AND operator. If both the operands
are non-zero, then the condition becomes true.
Called Logical OR Operator. If any of the two
operands is non-zero, then the condition becomes
true.
Called Logical NOT Operator. It is used to reverse
the logical state of its operand. If a condition is true,
then Logical NOT operator will make it false.

Example
(A && B) is false.
(A || B) is true.

!(A && B) is true.

Question: What is Operator? Briefly describe about different Operators of C Programming Language.
Operator:
An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C
language is rich in built-in operators and provides the following types of operators

Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators

Arithmetic Operators
The following table shows all the arithmetic operators supported by the C language. Assume variable A
holds 10 and variable B holds 20 then
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS
+88-01719-033364

Page 70 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Operator
+

*
/
%
++
--

Description
Adds two operands.
Subtracts second operand from the first.
Multiplies both operands.
Divides numerator by de-numerator.
Modulus Operator and remainder of after an integer
division.
Increment operator increases the integer value by
one.
Decrement operator decreases the integer value by
one.

Example
A + B = 30
A B = -10
A * B = 200
B/A=2
B%A=0
A++ = 11
A-- = 9

Relational Operators
The following table shows all the relational operators supported by C. Assume variable A holds 10 and
variable B holds 20 then
Operator
==
!=

>

<

>=

<=

Description
Checks if the values of two operands are equal or
not. If yes, then the condition becomes true.
Checks if the values of two operands are equal or
not. If the values are not equal, then the condition
becomes true.
Checks if the value of left operand is greater than the
value of right operand. If yes, then the condition
becomes true.
Checks if the value of left operand is less than the
value of right operand. If yes, then the condition
becomes true.
Checks if the value of left operand is greater than or
equal to the value of right operand. If yes, then the
condition becomes true.
Checks if the value of left operand is less than or
equal to the value of right operand. If yes, then the
condition becomes true.

Example
(A == B) is not true.
(A != B) is true.

(A > B) is not true.

(A < B) is true.

(A >= B) is not true.

(A <= B) is true.

Logical Operators
Following table shows all the logical operators supported by C language. Assume variable A holds 1
and variable B holds 0, then
Operator
&&
||

Description
Called Logical AND operator. If both the operands
are non-zero, then the condition becomes true.
Called Logical OR Operator. If any of the two
operands is non-zero, then the condition becomes
true.
Called Logical NOT Operator. It is used to reverse
the logical state of its operand. If a condition is true,
then Logical NOT operator will make it false.

Example
(A && B) is false.
(A || B) is true.

!(A && B) is true.

Bitwise Operators

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 71 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ is as
follows
p
0
0
1
1

q
0
1
1
0

p&q p|q
0
0
0
1
1
1
0
1

p^q
0
1
0
1

Assume A = 60 and B = 13 in binary format, they will be as follows


A = 0011 1100
B = 0000 1101
----------------A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
The following table lists the bitwise operators supported by C. Assume variable 'A' holds 60 and
variable 'B' holds 13, then
Operator
&
|
^
~
<<

>>

Description
Binary AND Operator copies a bit to the result if it
exists in both operands.
Binary OR Operator copies a bit if it exists in either
operand.
Binary XOR Operator copies the bit if it is set in one
operand but not both.
Binary Ones Complement Operator is unary and has
the effect of 'flipping' bits.
Binary Left Shift Operator. The left operands value is
moved left by the number of bits specified by the
right operand.
Binary Right Shift Operator. The left operands value
is moved right by the number of bits specified by the
right operand.

Example
(A & B) = 12, i.e., 0000 1100
(A | B) = 61, i.e., 0011 1101
(A ^ B) = 49, i.e., 0011 0001
(~A ) = -61, i.e,. 1100 0011 in 2's
complement form.
A << 2 = 240 i.e., 1111 0000

A >> 2 = 15 i.e., 0000 1111

Assignment Operators
The following table lists the assignment operators supported by the C language
Operator
=

Description
Simple assignment operator. Assigns values from
right side operands to left side operand

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 72 of 157

Example
C = A + B will assign the value of
A + B to C

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+=

-=

*=

/=

%=

<<=
>>=
&=
^=
|=

Add AND assignment operator. It adds the right


operand to the left operand and assign the result to
the left operand.
Subtract AND assignment operator. It subtracts the
right operand from the left operand and assigns the
result to the left operand.
Multiply AND assignment operator. It multiplies the
right operand with the left operand and assigns the
result to the left operand.
Divide AND assignment operator. It divides the left
operand with the right operand and assigns the
result to the left operand.
Modulus AND assignment operator. It takes modulus
using two operands and assigns the result to the left
operand.
Left shift AND assignment operator.
Right shift AND assignment operator.
Bitwise AND assignment operator.
Bitwise exclusive OR and assignment operator.
Bitwise inclusive OR and assignment operator.

C += A is equivalent to C = C + A

C -= A is equivalent to C = C - A

C *= A is equivalent to C = C * A

C /= A is equivalent to C = C / A

C %= A is equivalent to C = C %
A
C <<= 2 is same as C = C << 2
C >>= 2 is same as C = C >> 2
C &= 2 is same as C = C & 2
C ^= 2 is same as C = C ^ 2
C |= 2 is same as C = C | 2

Misc Operators sizeof & ternary


Besides the operators discussed above, there are a few other important operators including sizeof and
? : supported by the C Language.
Operator
sizeof()

Description
Returns the size of a variable.

&

Returns the address of a variable.

*
?:

Pointer to a variable.
Conditional Expression.

Example
sizeof(a), where a is integer, will
return 4.
&a; returns the actual address of
the variable.
*a;
If Condition is true ? then value X
: otherwise value Y

Operators Precedence in C
Operator precedence determines the grouping of terms in an expression and decides how an
expression is evaluated. Certain operators have higher precedence than others; for example, the
multiplication operator has a higher precedence than the addition operator.
For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher precedence
than +, so it first gets multiplied with 3*2 and then adds into 7.
Here, operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
Category
Postfix
Unary
Multiplicative
Additive
Shift
Relational

Operator
() [] -> . ++ - + - ! ~ ++ - - (type)* & sizeof
*/%
+<< >>
< <= > >=

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 73 of 157

Associativity
Left to right
Right to left
Left to right
Left to right
Left to right
Left to right

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Equality
Bitwise AND
Bitwise XOR
Bitwise OR
Logical AND
Logical OR
Conditional
Assignment
Comma

== !=
&
^
|
&&
||
?:
= += -= *= /= %=>>= <<= &= ^= |=
,

Left to right
Left to right
Left to right
Left to right
Left to right
Left to right
Right to left
Right to left
Left to right

Question: What do you mean by pseudo-code of a program? What are the advantages and Disadvantages
of Pseudo-Code? 5 October-2012
Pseudo-code of a program
Pseudocode is an informal high-level description of the operating principle of a computer
program or other algorithm. Pseudocode is a program analysis tool that is used for planning program
logic. "Pseudo" means imitation or false and "Code" refers to the instructions written in a programming
language. Pseudocode, therefore, is an imitation of actual computer instructions. These pseudo
instructions are phrases written in ordinary natural language (e.g., English, French, German, etc.).
Instead of using symbols to describe the logic steps of a program, as in flowcharting, pseudocode uses a
structure that resembles computer instructions. Because it emphasises the design of the program,
pseudocode is also called Program Design Language (PDL).
Pseudocode is made up of the following basic logic structures that have been proved to be sufficient for
writing any computer program :
1. Sequence
2. Selection (IF...THEN...ELSE or IF....THEN)
1. Iteration (DO...WHILE or REPEAT...UNTIL)
It uses the structural conventions of a programming language, but is intended for human reading rather
than machine reading. Pseudocode typically omits details that are essential for machine understanding
of the algorithm, such as variable declarations, system-specific code and some subroutines. The
programming language is augmented with natural language description details, where convenient, or
with compact mathematical notation. The purpose of using pseudocode is that it is easier for people to
understand than conventional programming language code, and that it is an efficient and environmentindependent description of the key principles of an algorithm. It is commonly used in textbooks and
scientific publications that are documenting various algorithms, and also in planning of computer
program development, for sketching out the structure of the program before the actual coding takes
place.
No standard for pseudocode syntax exists, as a program in pseudocode is not an executable program.
Pseudocode resembles, but should not be confused with skeleton programs which can be compiled
without errors. Flowcharts, drakon-charts and Unified Modeling Language (UML) charts can be thought
of as a graphical alternative to pseudocode, but are more spacious on paper.
Advantages of Pseudocodes
Pseudocode has three main advantages:
(a) Converting a pseudocode to a programming language is much more easier as compared to
converting a flowchart or a decision table.
(b) As compared to a flowchart, it is easier to modify the pseudocode of a program logic when program
modifications are necessary.
(c) Writing of pseudocode involves much less time and effort than drawing an equivalent flowchart.
Pseudocode is easier to write than an actual programming language because it has only a few rules to
follow, allowing the programmer to concentrate on the logic of the program.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 74 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Limitations of Pseudocodes
(a) In case of pseudocode, a graphic representation of program logic is not available.
(b) There are no standard rules to follow in using pseudocode. Different programmers use their own
style of writing pseudocode and hence communication problems occur due to lack of standardization.
(c) For a beginner, it is more difficult to follow the logic or write the pseudocode, as compared to
flowcharting.
Reference:
[1] http://www.gsd.inesc-id.pt/~jnos/programacao/2012-2013-1/docs/flowcharting.pdf
[2] https://en.wikipedia.org/wiki/Pseudocode

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 75 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What do you mean by the machine code of a CPU? 5 October-2012
Machine code of a CPU:
Machine code or machine language is a set of instructions executed directly by a computer's
central processing unit (CPU). Each instruction performs a very specific task, such as a load, a jump, or
an ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a
CPU is made up of a series of such instructions.
Numerical machine code (i.e., not assembly code) may be regarded as the lowest-level
representation of a compiled or assembled computer program or as a primitive and hardwaredependent programming language. While it is possible to write programs directly in numerical machine
code, it is tedious and error prone to manage individual bits and calculate numerical addresses and
constants manually. It is thus rarely done today, except for situations that require extreme optimization
or debugging.
Almost all practical programs today are written in higher-level languages or assembly
language and translated to executable machine code by utilities such as compilers, assemblers and
linkers. Programs in interpreted languages are not translated into machine code although their
interpreter (which may be seen as an executor or processor) typically consists of directly executable
machine code (generated from assembly or high level language source code).
Question: Write a loop that will run indefinitely. 2 April-2013
If we want to make something to loop forever use
either
1 for(;;){
2 //put the code you want to loop forever here.
3}
or
1 int temp = 0;
2 while (temp !=1){
3 /*
4 put the code you want to loop forever here.
5 Make sure you never put temp = 1 in the code you put.
6 */
7}

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 76 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: What are the Usages Of Continue And Break Statements In A Programming Language? 10 April2013
Usages Of Continue and Break Statements In A Programming Language:
There are two statements built in C programming, break; and continue; to alter the normal flow of a
program. Loops perform a set of repetitive task until text expression becomes false but it is sometimes
desirable to skip some statement/s inside loop or terminate the loop immediately without checking the
test expression. In such cases, break and continue statements are used. The break; statement is also used
in switch statement to exit switch statement.
break Statement
In C programming, break is used in terminating the loop immediately after it is encountered. The break
statement is used with conditional if statement.
Syntax of break statement
break;
The break statement can be used in terminating all three loops for, while and do...while loops.

The figure below explains the working of break statement in all three type of loops.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 77 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Example of break statement


Write a C program to find average of maximum of n positive numbers entered by user. But, if the input is
negative, display the average(excluding the average of negative input) and end the program.

/* C program to demonstrate the working of break statement by terminating a loop, if user inputs
negative number*/
# include <stdio.h>
int main(){
float num,average,sum;
int i,n;
printf("Maximum no. of inputs\n");
scanf("%d",&n);
for(i=1;i<=n;++i){
printf("Enter n%d: ",i);
scanf("%f",&num);
if(num<0.0)
break;
//for loop breaks if num<0.0
sum=sum+num;
}
average=sum/(i-1);
printf("Average=%.2f",average);
return 0;
}
Output
Maximum no. of inputs
4

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 78 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Enter n1: 1.5
Enter n2: 12.5
Enter n3: 7.2
Enter n4: -1
Average=7.07
In this program, when the user inputs number less than zero, the loop is terminated using break
statement with executing the statement below it i.e., without executing sum=sum+num.
In C, break statements are also used in switch...case statement. You will study it in C switch...case
statement chapter.
Continue Statement
It is sometimes desirable to skip some statements inside the loop. In such cases, continue statements
are used.
Syntax of continue Statement
continue;
Just like break, continue is also used with conditional if statement.

For better understanding of how continue statements works in C programming. Analyze the figure
below which bypasses some code/s inside loops using continue statement.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 79 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Example of continue statement


Write a C program to find the product of 4 integers entered by a user. If user enters 0 skip it.

//program to demonstrate the working of continue statement in C programming


# include <stdio.h>
int main(){
int i,num,product;
for(i=1,product=1;i<=4;++i){
printf("Enter num%d:",i);
scanf("%d",&num);
if(num==0)
continue; / *In this program, when num equals to zero, it skips the statement product*=num and
continue the loop. */
product*=num;
}
printf("product=%d",product);
return 0;
}

Output
Enter num1:3
Enter num2:0
Enter num3:-5
Enter num4:2
product=-30
Reference:
[1] http://www.programiz.com/c-programming/c-break-continue-statement

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 80 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart to find the sum of the first 50 natural numbers. 10 Marks October2010
Answer: The required flowchart is given in Fig. 1.

Fig. 1 Flowchart for the sum of the first 50 natural numbers

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 81 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart to find the largest of three numbers A, B, and C.
Answer: The required flowchart is shown in Fig 2

Fig 2 Flowchart for finding out the largest of three numbers

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 82 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart for computing factorial N (N!) Where N! = 1?2?3?....N .
Answer: The required flowchart has been shown in fig 3

Fig 3 Flowchart for computing factorial N

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 83 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: A student appears in an examination that consists of total 10 subjects, each subject having
maximum marks of 100. The roll number of the student, his name, and the marks obtained by him in
various subjects is supplied as input data. Such a collection of related data items that is treated as a unit is
known as a record. Draw a flow chart for the algorithm to calculate the percentage marks obtained by the
student in this examination and then to print it along with his roll number and name.

START
Enter Roll #
& Name
Enter a Subject
Obtained Marks

Loop 10 times

Add Ten Subject Marks Of


Each Student
& loop 10 times
Calculate a Percentages Of Each
Student Percentages =(Obtain
marks/Total marks)*100

Loop 10 times

Display a
Percentages Along
With Roll# &
Name
STOP

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 84 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: 50 students of a class appear in the problem 1. Draw a flowchart for the algorithm to calculate
and print the percentage marks obtained by each student along with his roll number.

START

Enter a Roll#,
Name &marks
Loop 50 times

Loop 50 times

Calculate a Percentages of
Each Student
Loop 50 time
Display a
Percentages Along
With Roll# &
Name
STOP

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 85 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flow chart of the logical steps needed to produce a printed listing of all students over the
age of 20 in a class. The input records contain the name and age of the students. Assume an initial value of
99 for the age field.

START
Enter a
Name & age

If
age
>20

Yes

Process on data

Display name
&age

STOP

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 86 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart of the logical steps needed to print the name and age of the oldest
and the youngest student in a class. The input records contain the name and age of the students.
8 April-2011 April-2009

START
Enter a
Name & age

Youngest

Oldest

Check
which
student is
young
which is old

Process on data
& loop

Process on data
& loop

Display Young
name &age

Display Young
name &age

STOP

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 87 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: A set of examination papers which have been graded with scores from 0 to 100 is to be searched
to find how many of them are above 90. The total is to be printed.

START

Enter scores
(0-100)

Yes Loop

If
scores
>90

No

Add total marks

Display total
marks

STOP

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 88 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flow chart to find the largest value of given numbers. 10 Marks October-2011

Reference:
[1] http://www.rff.com/find-largest-number.htm

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 89 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart for finding Prime Numbers. 10 Marks

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 90 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a Flow chart for finding the first 100 Prime Numbers.

Reference:
[1] http://www.rff.com/prime-numbers.htm

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 91 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a Flow Chart to find the N Factorial (N!).

Reference:
[1] http://www.rff.com/n_factorial_flowchart.htm

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 92 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: How do you draw a flowchart to calculate the first N Fibonacci numbers?

Reference:
[1] http://www.rff.com/fibonacci-numbers.htm

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 93 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Some Important Review Questions


Question: What is a flowchart?
A flowchart is a type of diagram that represents an algorithm or process, showing the
steps as boxes of various kinds, and their order by connecting these with arrows. This diagrammatic
representation can give a step-by-step solution to a given problem. Data is represented in these boxes,
and arrows connecting them represent flow / direction of flow of data. Flowcharts are used in analyzing,
designing, documenting or managing a process or program in various fields.
Question: How does a flowchart help a programmer in program development?
The flowchart is a means of visually presenting the flow of data through an information
processing systems, the operations performed within the system and the sequence in which they are
performed. In this lesson, we shall concern ourselves with the program flowchart, which describes what
operations (and in what sequence) are required to solve a given problem. The program flowchart can
be likened to the blueprint of a building. As we know a designer draws a blueprint before starting
construction on a building. Similarly, a programmer prefers to draw a flowchart prior to writing a
computer program. Flow chart is pictorial representation of the flow of the program, algorithm is step
by step procedure to solve a given problem.
Question: What are the characteristics necessary for a sequence of instructions to qualify as an algorithm?
Algorithms are essential to the way computers process information, because a computer
program is essentially an algorithm that tells the computer what specific steps to perform (in what
specific order) in order to carry out a specified task, such as calculating employees' paychecks or
printing students' report cards. Thus, an algorithm can be considered to be any sequence of operations
which can be performed by a Turing-complete system. Therefore, while designing an algorithm care
should be taken to provide a proper termination for algorithm. Thus, every algorithm should have the
following five characteristic features:
1.Input
2.Output
3.Definiteness
4.Effectiveness
5.Termination
Therefore, an algorithm can be defined as a sequence of definite and effective instructions, which
terminates with the production of correct output from the given input.
In other words, viewed little more formally, an algorithm is a step by step formalization of a mapping
function to map input set onto an output set.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 94 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Describe the function of the various flowcharting symbols?
Symbol

Symbol Name
(alias)
Process

Predefined
Process
(Subroutine)

Flow
Line
(Arrow,
Connector)
Decision

Connector
(Inspection)

Data
(I/O)

Symbol Description

Show a Process or action step. This is the most common


symbol in both process flowcharts and business process
maps.
A Predefined Process symbol is a marker for another
process step or series of process flow steps that are
formally defined elsewhere. This shape commonly
depicts sub-processes (or subroutines in programming
flowcharts). If the sub-process is considered "known" but
not actually defined in a process procedure, work
instruction, or some other process flowchart or
documentation, then it is best not to use this symbol since
it implies a formally defined process.
Flow line connectors show the direction that the process
flows.
Indicates a question or branch in the process flow.
Typically, a Decision flowchart shape is used when there
are 2 options (Yes/No, No/No-Go, etc.)
Flowchart: In flowcharts, this symbol is typically small
and is used as a Connector to show a jump from one point
in the process flow to another. Connectors are usually
labeled with capital letters (A, B, AA) to show matching
jump points. They are handy for avoiding flow lines that
cross other shapes and flow lines. They are also handy for
jumping to and from sub-processes defined in a separate
area
than
the
main
flowchart.
Process Mapping: In process maps, this symbol is full
sized and shows an Inspection point in the process flow.
[Just to confuse things further, some people will use a
circle to indicate an operation and a square to indicate an
inspection. That's why it's important to include a symbol
key in the flowchart.]
The Data flowchart shape indicates inputs to and outputs
from a process. As such, the shape is more often referred
to as an I/O shape than a Data shape.

Question: What is a record?


In computer data processing, a record is a collection of data items arranged for
processing by a program. Multiple records are contained in afield or data set. The organization of data
in the record is usually prescribed by the programming language that defines the record's organization
and/or by the application that processes it. Typically, records can be of fixed-length or be of variable
length with the length information contained within the record.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 95 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart to add up all the even numbers between . Before ending,
print the result of the calculation. 10 October-2009

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 96 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart to add up all the Odd numbers between . Before ending,
print the result of the calculation. 10 October-2009

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 97 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart to find the largest number among Three given numbers.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 98 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart to find the sum of first N Numbers.

Figure: Flowchart To Find Sum Of First N Numbers

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


+88-01719-033364

Page 99 of 157

S M TALHA JUBAED
+88-01911-088706

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart to find the sum of all numbers between . Before ending, print
the result of the calculation. 10 October-2009

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 100 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart to calculate the area of a square Triangle.

Question: Draw the flowchart to read 50 number then find the average.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 101 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 102 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Give a flow chart for the following problem. Read data values and keep on adding
them until negative value is entered. Output the sum. 10 April-2010

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 103 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart for adding marks in ten subjects obtained by a student in an examination. The
output should print the percentage of marks of the student in the examination.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 104 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Draw a flowchart for calculating the average percentage marks of 50 students. Each student
appeared in ten subjects. The flowchart should show the counting of the number of student who have
appeared in the examination and the calculation should stop when the number of counts reaches the
number 50.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 105 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: A set of examination papers, which have been graded with scores from to 100 is to
be searched to find how many of them are above 30. Prepare of flowchart to do this job.
10
April-2008

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 106 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Programming
Program-01: You have an array A of 100 elements. Write a program using any high level language of your
choice, which finds and displays the odd numbers of the array. April-2014

#include<stdio.h>
#include <iostream>
using namespace std;

int main(){
int number;
int min,max;
cout << "Enter the minimum range: ";
cin >> min;
cout << "Enter the maximum range: ";
cin >> max;
cout << "Odd numbers in given range are: ";
for(number = min;number <= max; number++)
if(number % 2 !=0)
cout << number<< " ";

return 0;
}
OUTPUT:

Enter the minimum range: 1


Enter the maximum range: 100
Odd numbers in given range are:1 3 5 7 9 11 13 15 17 19 21
23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61
63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

C program to print all odd numbers between 1 and 100


#include<stdio.h>
int main(){
int i;
for(i=1;i<100;i=i+2){
printf("%d\n",i);
}
}

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 107 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Supplementary Program for Students


C++ code to print all odd and even numbers in given range

#include<stdio.h>
#include <iostream>
using namespace std;

int main(){
int number;
int min,max;
cout << "Enter the minimum range: ";
cin >> min;
cout << "Enter the maximum range: ";
cin >> max;
cout << "Odd numbers in given range are: ";
for(number = min;number <= max; number++)
if(number % 2 !=0)
cout << number<< " ";
printf("\nEven numbers in given range are: ");
for(number = min;number <= max; number++)
if(number % 2 ==0)
cout << number << " ";
return 0;
}
OUTPUT:

Enter the minimum range: 2


Enter the maximum range: 25
Odd numbers in given range are: 3 5 7 9 11 13 15 17 19 21
23 25
Even numbers in given range are: 2 4 6 8 10 12 14 16 18 20
22 24
Reference:
[1]
even.html

http://programmingknowledgeblog.blogspot.com/2013/04/c-code-to-print-all-odd-and-

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 108 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

C++ program to print all odd numbers in given range


#include<iostream>
int main(){
int number;
int min,max;
cout << "Enter the minimum range: ";
cin >> min;
cout << "Enter the maximum range: ";
cin >> max;
cout << "Odd numbers in given range are: ";
for(number = min;number <= max; number++)
if(number % 2 !=0)
cout << number;
return 0;
}

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 109 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a small program in any of the languages to compute the sum of two real numbers and
display the result on the monitor. 10 April-2004 April-2005
C Programming Code:
#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter two numbers to add\n");
scanf("%d%d",&a,&b);
c = a + b;
printf("Sum of entered numbers = %d\n",c);
return 0;
}

Supplementary Code for Student


C++ Programming Code:
#include<iostream.h>
#include<conio.h>
void main()
{
int x,y,sum;
clrscr();
cout<<Enter first no: ;
cin>>x;
cout<<Enter second no: ;
cin>>y;
sum=x+y;
cout<<nSum = <<sum;
getch();
}

Similar Question: Write a program using C, C++ or FORTRAN which reads two integer numbers
from a keyboard and prints their sum to the computer console. 8 April-2005

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 110 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a program that reads in positive data until a negative number is entered and
calculates the summation of the positive entries and the number of data values read and added.
10 Marks April-2010
#include <stdio.h>
void main()
{
int num,sum;
clrscr();
printf("Enter positive numbers (0 or -ve number to stop):\n");
sum = 0;
scanf ("%d", &num);
while (num > 0)
{
sum += num;
scanf ("%d", &num);
}
printf ("Sum = %d ", sum);
getch();
}

Reference:
[1] http://ecomputernotes.com/what-is-c/control-structures/add-numbers-until-a-negativeor-zero-is-encountered

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 111 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a program that reads in positive data until a negative number is entered and
calculates the average and the maximum and minimum of the positive entries. 10 Marks
#include <iostream.h>
void main()
{
float value, sum;
float average, minimum, maximum;
int count;
// initialise
sum = 0.0;
count = 0;
cout << "Enter a value: ";
cin >> value;
minimum = value;
maximum = value;
while (value >= 0.0)
{
// process value
sum += value;
count++;
if (value > maximum)
maximum = value;
else if (value < minimum)
minimum = value;
// get next value
cout << "Enter a value: ";
cin >> value;
}
if (count == 0)
cout << "No data entry" << endl;
else
{
average = sum / count;
cout << "There were " << count <<
cout << "Average was " << average
cout << "Minimum was " << minimum
cout << "Maximum was " << maximum
}
}

" numbers" << endl;


<< endl;
<< endl;
<< endl;

Reference:
[1] https://www.macs.hw.ac.uk/~pjbk/pathways/cpp1/node122.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 112 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a program for the summing up first N positive integers using any programming
language. 10 October-2010
#include<stdio.h>
int add(int n);
int main()
{
int n;
printf("Enter an positive integer: ");
scanf("%d",&n);
printf("Sum = %d",add(n));
return 0;
}
int add(int n)
{
if(n!=0)
return n+add(n-1); /* recursive call */
}

Output
Enter an positive integer: 20
Sum = 210

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 113 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a program, using any high-level language, which reads three numbers from the keyboard,
and outputs the minimum and maximum values. Also write the output of the following program segment.
8 October-2013
int i, j, k;
k=2;
j = 10;
i = 5;
while( ) {
printf(i=%d, j=%d and k=%d, i, j, k);
j=j-2;
}
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\n Please enter the value of A: ");
scanf("%d",&a);
printf("\n Please enter the value of B: ");
scanf("%d",&b);
printf("\n Please enter the value of C: ");
scanf("%d",&c);
if (a<b && a<c)
printf("\n %d is Minimum which is value of A",a);
elseif(b<a && b<c)
printf("\n %d is Minimum which is value of B",b);
else
printf("\n %d is Minimum which is value of C",c);
if (a>b && a>c)
printf("\n\n %d is Maximum which is value of A",a);
elseif(b>a && b>c)
printf("\n\n %d is Maximum which is value of B",b);
else
printf("\n\n %d is Minimum which is value of C",c);
getch();
}
*********************** OUTPUT *************************************
Please enter the value of A: 47
Please enter the value of B: 25
Please enter the value of C: 96
25 is Minimum which isvalue of B
96 is Minimum which isvalue of C
********************************************************************

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 114 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Second Part:
Given Code Segment:
int i, j, k;
k=2;
j = 10;
i = 5;
while( ) {
printf(i=%d, j=%d and k=%d, i, j, k);
j=j-2;
}
Output:
i=5, j=10, k=2
i=5, j=8, k=2
i=5, j=6, k=2
i=5, j=4, k=2
i=5, j=2, k=2
Question: Write a program, using any high-level language, which asks the user to enter the radius of a
sphere, and then computes and displays the spheres area and volume where = 4 2 and =
4
3 . 8 October-2013
3
C program for area of a sphere

Formula of surface area of sphere:


Surface_area = 4 * Pie * r2
Formula of volume of sphere:
Volume = 4/3 * Pie * r3
Pie = 22/7 or 3.14159265358979323846264338327950288419716939937510...
C code:
#include<stdio.h>
#include<math.h>
int main(){
float r;
float surface_area,volume;

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 115 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


printf("Enter radius of the sphere : ");
scanf("%f",&r);
surface_area = 4* M_PI * r * r;
volume = (4.0/3) * M_PI * r * r * r;
printf("Surface area of sphere is: %.3f",surface_area);
printf("\nVolume of sphere is : %.3f",volume);
return 0;
}
Sample output:
Enter radius of the sphere: 5
Surface area of sphere is: 314.159
Volume of sphere is: 523.599

Reference:
[1] http://www.sanfoundry.com/c-program-volume-surface-area-sphere/
[2] http://www.cquestions.com/2011/07/write-c-program-to-find-volume-and_2200.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 116 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Similar Question: Write a C program to calculate area of a circle. 10 Marks
#include <stdio.h>
#define PI 3.141
int main(){
float r, a;
printf("Radius: ");
scanf("%f", &r);
a = PI * r * r;
printf("%f\n", a);
return 0;
}

Mathematical formula for area of circle:

Here Pie is constant which is equal to


Pie = 22/7 or 3.14159265358979323846264338327950288419716939937510...

Radius is radius of the circle.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 117 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question:Write A C Program To Find The Area Of A Triangle. 5 Marks

C program for area of a triangle

Formula of area of any triangle:


Area = (s*(s-a)*(s-b)*(s-c))
Where s = (a + b + c)/2
C code:
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c;
float s,area;
printf("Enter size of each sides of triangle");
scanf("%f%f%f",&a,&b,&c);
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle is: %.3f",area);
return 0;
}
Sample output:
Enter size of each sides of the triangle: 2 4 5
Area of triangle is: 3.800

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 118 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a C program to find the area of an equilateral triangle. 5 Marks

C program for area of equilateral triangle

Formula of area of equilateral triangle:


Area = (3)/4 * a2
C code:
#include<stdio.h>
#include<math.h>
int main(){
float a;
float area;
printf("Enter size of side of the equilateral triangle : ");
scanf("%f",&a);
area = sqrt(3)/4*(a*a);
printf("Area of equilateral triangle is: %.3f",area);
return 0;
}
Sample output:
Enter size of side of the equilateral triangle: 5
Area of equilateral triangle is: 10.825

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 119 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a C program to find the area of a right angled triangle. 5 Marks

C program for area of right angled triangle

Formula of area of right angled triangle:


Area = (1/2) * height * width
C code:
#include<stdio.h>
int main(){
float h,w;
float area;
printf("Enter height and width of the right angled triangle :
");
scanf("%f%f",&h,&w);
area = 0.5 * h * w;
printf("Area of right angled triangle is: %.3f",area);
return 0;
}
Sample output:
Enter height and width of the right angled triangle: 10 5
Area of right angled triangle is: 25.000

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 120 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a c program to find the area of a rectangle. 5 Marks

C program for area of a rectangle


Formula of area of rectangle:
Area = length * width
C code:
#include<stdio.h>
int main(){
float l,w;
float area;
printf("Enter size of each sides of the rectangle : ");
scanf("%f%f",&l,&w);
area = l * w;
printf("Area of rectangle is: %.3f",area);
return 0;
}
Sample output:
Enter size of each sides of the rectangle: 5.2 20
Area of rectangle is: 104.000

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 121 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Write a c program to find the area of a trapezium
C program for area of a trapezium

Formula of area of trapezium:


Area = (1/2) * (a + b) * h
C code:
#include<stdio.h>
int main(){
float b1,b2,h;
float area;
printf("Enter the size of two bases and height of the trapezium : ");
scanf("%f%f%f",&b1,&b2,&h);
area = 0.5 * ( b1 + b2 ) * h ;
printf("Area of trapezium is: %.3f",area);
return 0;
}
Sample output:
Enter the size of two bases and height of the trapezium: 5 8 3
Area of trapezium is: 19.500

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 122 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Write a c program to find the volume and surface area of a cube
C program for area of a cube

Formula of surface area of cube:


Surface_area = 6 * a2
Formula of volume of cube:
Volume = a3
C code:
#include<stdio.h>
int main(){
float a;
float surface_area,volume;
printf("Enter size of any side of a cube : ");
scanf("%f",&a);
surface_area = 6 * (a * a);
volume = a * a * a;
printf("Surface area of cube is: %.3f",surface_area);
printf("\nVolume of cube is : %.3f",volume);
return 0;
}
Sample output:
Enter size of any side of a cube: 3
Surface area of cube is: 54.000
Volume of cube is: 27.000

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 123 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Write a c program to find the volume and surface area of cuboids
C program for area of a cuboids

Formula of surface area of cuboids:


Surface_area = 2 *(w*l + l*h + h*w)
Formula of volume of cuboids:
Volume = w * l * h
Space diagonal of cuboids:
Space_diagonal = (w*w + l*l + h*h)
C code:
#include<stdio.h>
int main(){
float w,l,h;
float surface_area,volume,space_diagonal;
printf("Enter size of width, length and height of a cuboids : ");
scanf("%f%f%f",&w,&l,&h);
surface_area = 2*(w*l + l*h + h*w);
volume = w * l * h;
space_diagonal = sqrt(w*w + l*l + h*h);
printf("Surface area of cuboids is: %.3f",surface_area);
printf("\nVolume of cuboids is : %.3f",volume);
printf("\nSpace diagonal of cuboids is : %.3f",space_diagonal);
return 0;
}
Sample output:

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 124 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Enter size of width, length and height of cuboids: 5 10 4
Surface area of cuboids is: 220.000
Volume of cuboids is: 200.000
Space diagonal of cuboids is: 11.874

Write a c program to find the volume and surface area of cylinder


C program for area of a cylinder

Formula of surface area of cylinder:


Surface_area = 2 * Pie * r * (r + h)
Formula of volume of cylinder:
Volume = Pie * r * r * h
Pie = 22/7 or 3.14159265358979323846264338327950288419716939937510...
C code:
#include<stdio.h>
#include<math.h>
int main(){
float r,h;
float surface_area,volume;
printf("Enter size of radius and height of a cylinder : ");
scanf("%f%f",&r,&h);
surface_area = 2 * M_PI * r * (r + h);
volume = M_PI * r * r * h;
printf("Surface area of cylinder is: %.3f",surface_area);
printf("\nVolume of cylinder is : %.3f",volume);
return 0;
}
Sample output:

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 125 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Enter size of radius and height of a cylinder: 4 10


Surface area of cylinder is: 351.858
Volume of cylinder is: 502.655

Write a c program to find the volume and surface area of cone

Formula of surface area of cone:


Surface_area = Pie * r * (r + (r2 + h2))
Formula of volume of cone:
Volume = 1/3 * Pie * r2 * h
Pie = 22/7 or 3.14159265358979323846264338327950288419716939937510...
Write a c program or code to find or calculate the volume and surface area of cone
#include<stdio.h>
#include<math.h>
int main(){
float r,h;
float surface_area,volume;
printf("Enter size of radius and height of a cone : ");
scanf("%f%f",&r,&h);
surface_area = M_PI * r * (r + sqrt(r*r + h*h));
volume = (1.0/3) * M_PI * r * r * h;
printf("Surface area of cone is: %.3f",surface_area);
printf("\nVolume of cone is : %.3f",volume);
return 0;
}
Sample output:
Enter size of radius and height of a cone: 3 10
Surface area of cone is: 126.672

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 126 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Volume of cone is: 94.248
Write a c program to find the perimeter of a circle, rectangle and triangle
Formula of perimeter of different shapes in geometry:
1. Square = 4 * a
2. Rectangle: 2 * (a + b)
3. General triangle: a + b + c
4. Equilateral triangle: 3 * a
5. Right angled triangle: w + l + (w2 + l2)
6. Circle: 2 * * r
7. Parallelogram: 2 * (a + b)
8. Rhombus: 4 * a
9. Cube: 12 * a
10. Cuboids: 4 * (w + l + h)
11. Trapezium: a + b + c + d
12. Equilateral polygon: n * a
13. Regular polygon: 2 * n * a sin ( /n)
14. General polygon: a1 + a2 + a3 + + an
C code:

#include<stdio.h>
#include<math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
int main(){
float r,l,w,h,a,b,c;
int n;
float perimeter;
//Perimeter of square
printf("Enter the size of any side square : ");
scanf("%f",&a);
perimeter = 4 * a;
printf("Perimeter of square is: %.3f",perimeter);
//Perimeter of rectangle
printf("\n\nEnter width and length of the rectangle : ");
scanf("%f%f",&w,&l);
perimeter = 2 * (w +l);
printf("Perimeter of rectangle is: %.3f",perimeter);
//Perimeter of triangle
printf("\n\nEnter the size of all sides of the triangle : ");
scanf("%f%f%f",&a,&b,&c);
perimeter = a + b + c;
printf("Perimeter of triangle is: %.3f",perimeter);
//Perimeter of circle
printf("\n\nEnter the radius of the circle : ");
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 127 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


scanf("%f",&r);
perimeter = 2 * M_PI * r;
printf("Perimeter of circle is: %.3f",perimeter);
//Perimeter of cuboids
printf("\n\nEnter width, length and height of the cuboids : ");
scanf("%f%f%f",&w,&l,&h);
perimeter = 4 * (w + l + h);
printf("Perimeter of cuboids is: %.3f",perimeter);
//Perimeter of cube
printf("\n\nEnter any side of the cube : ");
scanf("%f",&a);
perimeter = 12 * a;
printf("Perimeter of cube is: %.3f",perimeter);
//Perimeter of rhombus
printf("\n\nEnter any side of the rhombus : ");
scanf("%f",&a);
perimeter = 4 * a;
printf("Perimeter of rhombus is: %.3f",perimeter);
//Perimeter of parallelogram
printf("\n\nEnter size of any two consecutive side of parallelogram : ");
scanf("%f%f",&a,&b);
perimeter = 2 *(a + b);
printf("Perimeter of parallelogram is: %.3f",perimeter);
//Perimeter of equilateral triangle
printf("\n\nEnter any side of the equilateral triangle : ");
scanf("%f",&a);
perimeter = 3 * a;
printf("Perimeter of equilateral triangle is: %.3f",perimeter);
//Perimeter of right angled triangle
printf("\n\nEnter the width and height of the right angled triangle : ");
scanf("%f%f",&w,&h);
perimeter = w + h + sqrt(w*w + h*h);
printf("Perimeter of right angled triangle is: %.3f",perimeter);
//Perimeter of equilateral polygon
printf("\n\nEnter the any side of the equilateral polygon : ");
scanf("%f",&a);
printf("Enter the total numbers of sides of equilateral polygon : ");
scanf("%d",&n);
perimeter = n * a;
printf("Perimeter of equilateral polygon is: %.3f",perimeter);
//Perimeter regular polygon
printf("\n\nEnter the total number of sides in the regular polygon : ");
scanf("%d",&n);
printf("Enter the distance between any vertex and center of the regular polygon : ");
scanf("%f",&a);
perimeter = 2 * n * a * sin(M_PI/n);
printf("Perimeter of regular polygon is: %.3f",perimeter);

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 128 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


//Perimeter of general polygon
printf("\n\nEnter size of sides of the general polygon. To exit enter zero : ");
perimeter = 0;
while(1){
scanf("%f",&a);
if(a < 1)
break;
else
perimeter = perimeter + a;
}
printf("Perimeter of general polygon is: %.3f",perimeter);
return 0;
}

Sample output:
Enter the size of any side square: 4
Perimeter of square is: 16.000
Enter width and length of the rectangle: 4 8
Perimeter of rectangle is: 24.000
Enter the size of all sides of the triangle: 3 4 5
Perimeter of triangle is: 12.000
Enter the radius of the circle: 4
Perimeter of circle is: 25.133
Enter width, length and height of the cuboids: 5 10 15
Perimeter of cuboids is: 120.000
Enter any side of the cube: 4
Perimeter of cube is: 48.000
Enter any side of the rhombus: 4
Perimeter of rhombus is: 16.000
Enter size of any two consecutive side of parallelogram: 4 8
Perimeter of parallelogram is: 24.000
Enter any side of the equilateral triangle: 3
Perimeter of equilateral triangle is: 9.000
Enter the width and height of the right angled triangle: 5 12
Perimeter of right angled triangle is: 30.000
Enter the any side of the equilateral polygon: 5
Enter the total numbers of sides of equilateral polygon: 8
Perimeter of equilateral polygon is: 40.000
Enter the total number of sides in the regular polygon: 6
Enter the distance between any vertex and center of the regular polygon: 11
Perimeter of regular polygon is: 66.000

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 129 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Enter size of sides of the general polygon. To exit enter zero: 5 7 2 9 0
Perimeter of general polygon is: 23.000

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 130 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a program to find the Maximum, Minimum and Summation of 50 numbers. 10 October2014
#include<stdio.h>
int main()
{
float average;
int i, n, count=0, sum=0, num, min, max;
while(count<50)
{
min=0;
max=0;
if(num>max)
max=num;
if(num<min)
min=num;
scanf_s("%d",&num);
sum = sum+num;
count++;
}
average = 1.0*sum/n;
printf("The sum of your numbers is %d\n",sum);
printf("Your maximum number is %d\n",max);
printf("Your minimum number is %d\n",min);
return(0);
}

Question: Write a program to find the largest value of given numbers using any programming language.
10 October-2011
Simple program of C find the largest number
#include<stdio.h>
int main(){
int n,num,i;
int big;
printf("Enter the values of n: ");
scanf("%d",&n);
printf("Number %d",1);
scanf("%d",&big);
for(i=2;i<=n;i++){
printf("Number %d: ",i);
scanf("%d",&num);
if(big<num)
big=num;
}

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 131 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


printf("Largest number is: %d",big);
return 0;
}

Sample Output:
Enter the values of n:
Number 1: 12
Number 2: 32
Number 3: 35
Largest number is: 35

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 132 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Given an integer, write a program to find the summation of all digits of the given integer
number. 8 October-2012
C Program To Find Out Sum Of Digit Of Given Number
Code 1:
1. C program to add digits of a number
2. C program for sum of digits of a number
3. C program to calculate sum of digits
#include<stdio.h>
int main(){
int num,sum=0,r;
printf("Enter a number: ");
scanf("%d",&num);
while(num){
r=num%10;
num=num/10;
sum=sum+r;
}
printf("Sum of digits of number: %d",sum);
return 0;
}

Sample output:
Enter a number: 123
Sum of digits of number: 6
Code 2:
1. Sum of digits of a number in c using for loop
#include<stdio.h>
int main(){
int num,sum=0,r;
printf("Enter a number: ");
scanf("%d",&num);
for(;num!=0;num=num/10){
r=num%10;
sum=sum+r;
}
printf("Sum of digits of number: %d",sum);
return 0;
}

Sample output:
Enter a number: 567
Sum of digits of number: 18
Code 3:
1. Sum of digits in c using recursion
#include<stdio.h>

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 133 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


int getSum(int);
int main(){
int num,sum;
printf("Enter a number: ");
scanf("%d",&num);
sum = getSum(num);
printf("Sum of digits of number: %d",sum);
return 0;
}
int getSum(int num){
static int sum =0,r;
if(num!=0){
r=num%10;
sum=sum+r;
getSum(num/10);
}
return sum;
}

Sample output:
Enter a number: 45
Sum of digits of number: 9
Reference:
[1] http://www.cquestions.com/2010/06/write-c-program-to-find-out-sum-of.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 134 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a program to swap the values of two variables. 4 October-2012
C Program For Swapping Of Two Numbers:
Code for swapping in c
#include<stdio.h>
int main(){
int a,b,temp;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
printf("Before swapping: a = %d, b=%d",a,b);
temp = a;
a = b;
b = temp;
printf("\nAfter swapping: a = %d, b=%d",a,b);
return 0;
}
C program for swapping of two numbers using pointers
#include<stdio.h>
int main(){
int a,b;
int *ptra,*ptrb;
int *temp;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
printf("Before swapping: a = %d, b=%d",a,b);
ptra = &a;
ptrb = &b;
temp = ptra;
*ptra = *ptrb;
*ptrb = *temp;
printf("\nAfter swapping: a = %d, b=%d",a,b);
return 0;
}

Sample output:
Enter any two integers: 5 10
Before swapping: a = 5, b=10
After swapping: a = 10, b=10

Swapping program in c using function

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 135 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

#include<stdio.h>
void swap(int *,int *);
int main(){
int a,b;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
printf("Before swapping: a = %d, b=%d",a,b);
swap(&a,&b);
printf("\nAfter swapping: a = %d, b=%d",a,b);
return 0;
}
void swap(int *a,int *b){
int *temp;
temp = a;
*a=*b;
*b=*temp;
}

Sample output:
Enter any two integers: 3 6
Before swapping: a = 3, b=6
After swapping: a = 6, b=6
Reference:
[1] http://www.cquestions.com/2011/09/c-program-for-swapping-of-two-numbers.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 136 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a Program to Reverse Any given Number. 10 Marks
Reverse Any Number Using C Program:
Code 1:
1. Write a c program to reverse a given number
2. C program to find reverse of a number
3. C program to reverse the digits of a number
4. Reverse of a number in c using while loop
#include<stdio.h>
int main(){
int num,r,reverse=0;
printf("Enter any number: ");
scanf("%d",&num);
while(num){
r=num%10;
reverse=reverse*10+r;
num=num/10;
}
printf("Reversed of number: %d",reverse);
return 0;
}

Sample output:
Enter any number: 12
Reversed of number: 21
Code 2:
1. Reverse very large or big numbers beyond the range of long int
2. Reverse five digit number c program
Logic is we accept the number as string
#include<stdio.h>
#define MAX 1000
int main(){
char num[MAX];
int i=0,j,flag=0;
printf("Enter any positive integer: ");
scanf("%s",num);
while(num[i]){
if(num[i] < 48 || num[i] > 57){
printf("Invalid integer number");
return 0;
}
i++;
}

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 137 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

printf("Reverse: ");
for(j=i-1;j>=0;j--)
if(flag==0 && num[j] ==48){
}
else{
printf("%c",num[j]);
flag =1;
}
return 0;

Sample output:
Enter any positive integer: 234561000045645679001237800000000000
Reverse: 8732100976546540000165432
Code 3:
1. C program to reverse a number using for loop
2. How to find reverse of a number in c
3. Wap to reverse a number in c
#include<stdio.h>
int main(){
int num,r,reverse=0;
printf("Enter any number: ");
scanf("%d",&num);
for(;num!=0;num=num/10){
r=num%10;
reverse=reverse*10+r;
}
printf("Reversed of number: %d",reverse);
return 0;
}
Sample output:
Enter any number: 123
Reversed of number: 321
Code 4:
1. C program to reverse a number using recursion
#include<stdio.h>
int main(){
int num,reverse;
printf("Enter any number: ");
scanf("%d",&num);
reverse=rev(num);
printf("Reverse of number: %d",reverse);
return 0;

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 138 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


}
int rev(int num){
static sum,r;
if(num){
r=num%10;
sum=sum*10+r;
rev(num/10);
}
else
return 0;
return sum;
}

Sample output:
Enter any number: 456
Reverse of number: 654
Reference:
[1] http://www.cquestions.com/2008/01/c-program-to-reverse-any-number.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 139 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a Program to find the power of a Given Number. 10 Marks
Find Power Of A Number Using C Program:
#include<stdio.h>
int main(){
int pow,num,i=1;
long int sum=1;
printf("\nEnter a number: ");
scanf("%d",&num);
printf("\nEnter power: ");
scanf("%d",&pow);
while(i<=pow){
sum=sum*num;
i++;
}
printf("\n%d to the power %d is: %ld",num,pow,sum);
return 0;
}

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 140 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a Program to add Two Numbers without using Addition Operator. 10 Marks
Add Two Numbers In C Without Using Operator:
#include<stdio.h>
int main(){
int a,b;
int sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
//sum = a - (-b);
sum = a - ~b -1;
printf("Sum of two integers: %d",sum);
return 0;
}

Sample output:
Enter any two integers: 5 10
Sum of two integers: 15

Algorithm:
In c ~ is 1's complement operator. This is equivalent to:
~a = -b + 1
So, a - ~b -1
= a-(-b + 1) + 1
= a + b 1 + 1
= a + b
Reference:
[1] http://www.cquestions.com/2011/07/write-c-program-to-add-two-numbers.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 141 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a Program to subtract Two Numbers without using Subtraction Operator. 10 Marks
Subtract Two Numbers In C Without Using Operator:
#include<stdio.h>
int main(){
int a,b;
int sum;
printf("Enter any two integers: ");
scanf("%d%d",&a,&b);
sum = a + ~b + 1;
printf("Difference of two integers: %d",sum);
return 0;
}

Sample Output:
Enter any two integers: 5 4
Difference of two integers: 1
Reference:
[1] http://www.cquestions.com/2011/07/write-c-program-to-subtract-two-numbers.html
Question: Write a c program to find largest among three numbers using binary minus operator. 10
Marks
#include<stdio.h>
int main(){
int a,b,c;
printf("\nEnter 3 numbers: ");
scanf("%d %d %d",&a,&b,&c);
if(a-b>0 && a-c>0)
printf("\nGreatest is a :%d",a);
else
if(b-c>0)
printf("\nGreatest is b :%d",b);
else
printf("\nGreatest is c :%d",c);
return 0;
}

Reference:
[1] http://www.cquestions.com/2010/06/write-c-program-to-find-largest-among.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 142 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a c program to find largest among three numbers using conditional operator. 10 Marks
#include<stdio.h>
int main(){
int a,b,c,big;
printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);
big=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is: %d",big);
return 0;
}
Reference:
[1] http://www.cquestions.com/2010/06/write-c-program-to-find-largest-among_19.html
Question: Write a program to Split number into digits in c programming. 10 Marks
#include<stdio.h>
int main(){
int num,temp,factor=1;
printf("Enter a number: ");
scanf("%d",&num);
temp=num;
while(temp){
temp=temp/10;
factor = factor*10;
}
printf("Each digits of given number are: ");
while(factor>1){
factor = factor/10;
printf("%d ",num/factor);
num = num % factor;
}
return 0;
}

Sample output:
Enter a number: 123
Each digits of given number are: 1 2 3
Reference:
[1] http://www.cquestions.com/2011/09/split-number-into-digits-in-c.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 143 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a Program to count number of digits in a number. 10 Marks
Code 1:
Count the number of digits in c programming language
#include<stdio.h>
int main(){
int num,count=0;
printf("Enter a number: ");
scanf("%d",&num);
while(num){
num=num/10;
count++;
}
printf("Total digits is:
return 0;

%d",count);

Sample output:
Enter a number: 23
Total digits is: 2
Code 2:
C code to count the total number of digit using for loop
#include<stdio.h>
int main(){
int num,count=0;
printf("Enter a number: ");
scanf("%d",&num);
for(;num!=0;num=num/10)
count++;
printf("Total digits is:

%d",count);

return 0;
}

Sample output:
Enter a number: 456
Total digits is: 3

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 144 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Code 3:
Count the digits of a given number in c language using recursion
#include<stdio.h>
int countDigits(num);
int main(){
int num,count;
printf("Enter a number: ");
scanf("%d",&num);
count = countDigits(num);
printf("Total digits is:
return 0;

%d",count);

}
int countDigits(int num){
static int count=0;
if(num!=0){
count++;
countDigits(num/10);
}
return count;
}

Sample output:
Enter a number: 1234567
Total digits is: 7
Reference:
[1] http://www.cquestions.com/2011/09/c-program-to-count-number-of-digits-in.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 145 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write A Program To Find Prime Factors Of A Number Using C Program.
#include<stdio.h>
int main(){
int num,i=1,j,k;
printf("\nEnter a number:");
scanf("%d",&num);
while(i<=num){
k=0;
if(num%i==0){
j=1;
while(j<=i){
if(i%j==0)
k++;
j++;
}
if(k==2)
printf("\n%d is a prime factor",i);
}
i++;
}
return 0;
}

Reference:
[1] http://www.cquestions.com/2008/01/write-c-program-to-find-prime-factors.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 146 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a program to find summation, average, maximum and minimum of numbers. 8 April2013
Program To Find Sum, Average, Maximum And Minimum Number Of Array:
#include<stdio.h>
int max (int [][5]);
int min (int [][5]);
int main()
{
int c[2][5];
int i,j;
float sum=0;
printf("Please enter elements of 2-D array of 2 rows and 5 columns:");
for(i=0;i<2;i++)
{
for(j=0;j<5;j++)
{
scanf("%d",&c[i][j]);
sum=sum+c[i][j];
}
}
printf("Your elemnts are\n\n");
for(i=0;i<2;i++)
{
for(j=0;j<5;j++)
{
printf("%8d\n",c[i][j]);
}
}
printf("\nSum of your array is : %.2f \n",sum);
printf("Maximum Number of your array is : %d \n",max (c));
printf("Minimum Number of your array is : %d \n",min (c));
printf("Average Number of your array is : %.2f \n",sum/10);
getch();
return 0;
}

int max (int c[][5])


{
int i,j;
int maxi=c[0][0];
for (i=0;i<2;i++)
{
for(j=0;j<5;j++)
{
if (maxi<c[i][j])
maxi =c[i][j];
}
}
return maxi;
}
int min (int c[][5])
COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 147 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


{
int i,j;
int mini=c[0];
for (i=0;i<2;i++)
{
for(j=0;j<5;j++)
{
if (mini>c[i][j])
mini =c[i][j];
}
}
return mini;
}

Reference:
[1] http://letusprogrm.blogspot.com/2013/12/include-int-max-int-5-int-min-int-5-int.html

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 148 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a program that takes an year as an input, and gives yes as output if the given year is a
leap year and No as output if the year is not a leap year. 5 April-2013
Source Code to Check Leap Year

/* C program to check whether a year is leap year or not using if else statement.*/
#include <stdio.h>
int main(){
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0) /* Checking for a century year */
{
if ( year%400 == 0)
printf("Yes ! %d is a leap year.", year);
else
printf("No ! %d is not a leap year.", year);
}
else
printf("Yes ! %d is a leap year.", year );
}
else
printf("No ! %d is not a leap year.", year);
return 0;
}
Output 2

Enter year: 1900


1900 is not a leap year.
Output 3

Enter year: 2012


Yes ! 2012 is a leap year.

Reference:
[1] http://www.programiz.com/c-programming/examples/leap-year

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 149 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS


Question: Write a function to find the length of a given string. 3 April-2013
#include <stdio.h>
int main()
{
char s[1000],i;
printf("Enter a string: ");
scanf("%s",s);
for(i=0; s[i]!='\0'; ++i);
printf("Length of string: %d",i);
return 0;
}
Output
Enter a string: Programiz
Length of string: 9
Reference:
[1] http://www.programiz.com/c-programming/examples/string-length

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 150 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Some Basic C Program for AMIE Students


Source Code to Check Whether a Number is Even or Odd
/*C program to check whether a number entered by user is even or odd. */
#include <stdio.h>
int main(){
int num;
printf("Enter an integer you want to check: ");
scanf("%d",&num);
if((num%2)==0)
/* Checking whether remainder is 0 or not. */
printf("%d is even.",num);
else
printf("%d is odd.",num);
return 0;
}

Output 1
Enter an integer you want to check: 25
25 is odd.

Output 2
Enter an integer you want to check: 12
12 is even.

Reference:
[1] http://www.programiz.com/c-programming/examples/even-odd

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 151 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Source Code to Check Whether a Number is Positive or


Negative
#include <stdio.h>
int main()
{
float num;
printf("Enter a number: ");
scanf("%f",&num);
if (num<=0)
{
if (num==0)
printf("You entered zero.");
else
printf("%.2f is negative.",num);
}
else
printf("%.2f is positive.",num);
return 0;
}

This program also can be solved using nested if else statement.


/* C programming code to check whether a number is negative or positive or zero
using nested if...else statement. */
#include <stdio.h>
int main()
{
float num;
printf("Enter a number: ");
scanf("%f",&num);
if (num<0)
/* Checking whether num is less than 0*/
printf("%.2f is negative.",num);
else if (num>0)
/* Checking whether num is greater than zero*/
printf("%.2f is positive.",num);
else
printf("You entered zero.");
return 0;
}

Output 1
Enter a number: 12.3
12.30 is positive.

Output 2
Enter a number: 0
You entered zero.

Reference:
[1] http://www.programiz.com/c-programming/examples/negative-positive-zero

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 152 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Source Code to Calculate Sum of Natural Numbers


/* This program is solved using while loop. */
#include <stdio.h>
int main()
{
int n, count, sum=0;
printf("Enter an integer: ");
scanf("%d",&n);
count=1;
while(count<=n)
/* while loop terminates if count>n */
{
sum+=count;
/* sum=sum+count */
++count;
}
printf("Sum = %d",sum);
return 0;
}

Source Code to Calculate Sum Using for Loop


/* This program is solve using for loop. */
#include <stdio.h>
int main()
{
int n, count, sum=0;
printf("Enter an integer: ");
scanf("%d",&n);
for(count=1;count<=n;++count)
{
sum+=count;
}
printf("Sum = %d",sum);
return 0;
}

/* for loop terminates if count>n */


/* sum=sum+count */

Output
Enter an integer: 100
Sum = 5050

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 153 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

C program to Check Prime Number


/* C program to check whether a number is prime or not. */
#include <stdio.h>
int main()
{
int n, i, flag=0;
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=2;i<=n/2;++i)
{
if(n%i==0)
{
flag=1;
break;
}
}
if (flag==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
return 0;
}

Output
Enter a positive integer: 29
29 is a prime number.

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 154 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

C Program to Check Palindrome Number


/* C program to check whether a number is palindrome or not */
#include <stdio.h>
int main()
{
int n, reverse=0, rem,temp;
printf("Enter an integer: ");
scanf("%d", &n);
temp=n;
while(temp!=0)
{
rem=temp%10;
reverse=reverse*10+rem;
temp/=10;
}
/* Checking if number entered by user and it's reverse number is equal. */
if(reverse==n)
printf("%d is a palindrome.",n);
else
printf("%d is not a palindrome.",n);
return 0;
}

Output
Enter an integer: 12321
12321 is a palindrome.

Reference:
[1] http://www.programiz.com/c-programming/examples/palindrome-number

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 155 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Source Code to Display Prime Numbers Between two


Intervals
/* C program to display all prime numbers between Two interval entered by user.
*/
#include <stdio.h>
int main()
{
int n1, n2, i, j, flag;
printf("Enter two numbers(intevals): ");
scanf("%d %d", &n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
for(i=n1+1; i<n2; ++i)
{
flag=0;
for(j=2; j<=i/2; ++j)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("%d ",i);
}
return 0;
}

Output
Enter two numbers(intervals): 20
50
Prime numbers between 20 and 50 are: 23 29 31 37 41 43 47

Reference:
[1]
intervals

http://www.programiz.com/c-programming/examples/prime-number-

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 156 of 157

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

Source Code to Calculate Average Using Arrays


#include <stdio.h>
int main(){
int n, i;
float num[100], sum=0.0, average;
printf("Enter the numbers of data: ");
scanf("%d",&n);
while (n>100 || n<=0)
{
printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d",&n);
}
for(i=0; i<n; ++i)
{
printf("%d. Enter number: ",i+1);
scanf("%f",&num[i]);
sum+=num[i];
}
average=sum/n;
printf("Average = %.2f",average);
return 0;
}

Output
Enter the numbers of data: 6
1. Enter number: 45.3
2. Enter number: 67.5
3. Enter number: -45.6
4. Enter number: 20.34
5. Enter number: 33
6. Enter number: 45.6
Average = 27.69

Reference:
[1] http://www.programiz.com/c-programming/examples/average-arrays

C Program to Accept two Integers and Check if they are Equal


1. /*
2. * C program to accept two integers and check if they are equal
3. */
4. #include <stdio.h>
5. void main()
6. {
7.
int m, n;
8.
9.
printf("Enter the values for M and N\n");
10.
scanf("%d %d", &m, &n);
11.
if (m == n)
12.
printf("M and N are equal\n");
13.
else
14.
printf("M and N are not equal\n");
15. }

Reference:
[1] http://www.sanfoundry.com/c-program-two-integers-equal/

COMPUTER FUNDAMENTALS INTRODUCTION TO COMPUTERS

S M TALHA JUBAED

+88-01719-033364

+88-01911-088706

Page 157 of 157

Vous aimerez peut-être aussi