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

Computer Programing notes

The document provides a comprehensive overview of computer programming, detailing types of programming languages (lower level, assembly, and higher level), flowcharts, features of C language, data types, operators, and various programming concepts. It includes explanations of flowcharts, their symbols, limitations, and examples of programming tasks such as calculating sums and checking for leap years. Additionally, it discusses branching in programming and provides examples of common programming errors and their corrections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Computer Programing notes

The document provides a comprehensive overview of computer programming, detailing types of programming languages (lower level, assembly, and higher level), flowcharts, features of C language, data types, operators, and various programming concepts. It includes explanations of flowcharts, their symbols, limitations, and examples of programming tasks such as calculating sums and checking for leap years. Additionally, it discusses branching in programming and provides examples of common programming errors and their corrections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

COMPUTER PROGRAMING QUESTION BANK

1) Explain Types of Computer Programming and its characteristics.

There are three different types of programming language in computer.


1. Lower level Language (Machine Level Language)
2. Assembly Language
3. Higher Level Language

1. Lower level Language:


 It is also called machine level programming language because programs can be
written by using binary code (0 or 1) and machine (computer) understands only
binary codes not human readable code.
 Programs are machine dependent because binary codes vary from machine to
machine or processor to processor.
 Programs written in this language are not portable because programs written
using binary codes of one machine will not work on other machine.
 This language is not comfortable for humans because it is very difficult for human
being to remember binary codes for 100 to 200 different operations. Humans are
more comfortable with textual information rather than numeric information. That
means it is easy to remember names of 10 persons but hardly remember contact
numbers of that 10 persons.
Characteristics: 
 Computers can understand and execute it directly.
 It uses binary codes.
 Programs are machine dependent.
 It is not comfortable for human.
 It is time consuming.
 Programs are not portable
2. Assembly Language:
 Programs are written using mnemonics/Instruction codes are known as Assembly
language Programs.
 This language is used to solve the problem of remembering different binary codes.
Programs are processor dependent because mnemonics or instruction codes vary
from processor to processor.
 Programs written in this language are not portable because programs written in
one assembly language of one processor will not work on other processor.
 This language is not comfortable for humans because it requires knowledge of
architecture of different processor. But all humans do not have such knowledge.
 Assembler is a software tool which is used to translate assembly language
program into corresponding machine language program.

Characteristics:

 It uses mnemonics or instruction codes


 Programs are processor dependent
 It is not comfortable for human
 Programs are not portable
 It requires software tool such as assembler.
COMPUTER PROGRAMING QUESTION BANK

3) Higher level Language:


 It is like natural English like language because it uses phrases of natural language.
Programs are machine as well as processor independent.
 It is comfortable for human because programs are easy to understand. Programs
written using such language are portable that means program written on one
computer can easily transfer to another computer without any modification in
program.
 Basic, Cobol, Fortran, C, C++, Java all are examples of higher level language.
Compiler is a software tool which is used to translate higher level language into
machine level language.
 Interpreter is another software tool which is also used to translate higher level
language into machine level language but it executes the code line by line.

Characteristics:

 It uses natural language like English


 Programs are machine as well as processor independent
 It is comfortable for human
 Programs are portable
 It requires software tool such as compiler or interpreter
 It is easy to understand.
 Program development becomes simpler and faster.
 Productivity is much higher and software can be developed in short period.

Q-2 what is Flowchart and explain its symbol and limitation.


Flowcharts:

 A flowchart is a pictorial or graphical representation of an algorithm. It is easier to


understand and develop because it represents solution in form of pictures. It
shows flow of data within solution.

 Symbol of Flowcharts:
COMPUTER PROGRAMING QUESTION BANK

Limitation of Flowcharts:
1. If program logic is quite complicated, the flowchart becomes complex.

2. If alterations are required, the flowchart may require re-drawing completely, it becomes
COMPUTER PROGRAMING QUESTION BANK

Time consuming.

3. Reproduction of flowchart becomes a problem because flowchart symbols cannot be


typed.
4. Essentials information in problem can be lost.

Q-3 Draw flowchart to calculate addition of 1 to 10 numbers.


COMPUTER PROGRAMING QUESTION BANK

Q-4 Draw Flowchart to find the area of rectangle.


COMPUTER PROGRAMING QUESTION BANK

Q-5 Differentiate the terms program and programming.


COMPUTER PROGRAMING QUESTION BANK

Q-6 Draw a flowchart to print ODD numbers between 1 to N. Value of N is to be read from
standard input (keyboard).

Q-7 Explain Features of ‘C’ Language.

The main features of C language are as follows

1. Easy to learn C is a higher level language normally written in Natural Language. So it can be
easily understand by any programmer.
2. . More efficient more complex and large program can be easily made and run.
3. 3. Faster than any other basic language C does not contain input/output statements. But for
input/output operation, C uses library functions like scanf () and printf (). Other programming
language contains input/output statements. So, C is faster than any other basic language such
as Cobol, Pascal and Fortran.
4. 4. Portable C is developed to solve portability problem in UNIX. Programs are written using C
language is portable. That means C program written on one computer can transfer to other
computer without any modification in program or with little modification required.
5. Procedural oriented programming language Procedural Oriented means Function based
Programming. Large program can be divided into smaller sub programs. These sub programs
are called functions. So C program are written in form of functions. Each function can be easily
understand and managed.
6. Structured/Modular programming language If program is small, then it is easily understand
and managed. But if program is large, then it is hard to understand. So dividing large program
into smaller sub programs make it easy to understand and maintain. These smaller sub
COMPUTER PROGRAMING QUESTION BANK

programs are called module. The process of dividing a program into smaller sub programs is
called modularity. So, C is called modular programming language.
7. It support bit-wise operation C support bit-wise operations such as AND, OR, NOT operation
etc. but these operations are not supported by higher level language. It is supported by lower
level/assembly language. For this reason, C is not considered as fully or true higher level
language. But it is known as Middle level language. It provides features of both higher as well
as lower level language.

Q-8 What is a Data Type and explain three Data Types in details..?

C Language is rich in its data types. Data types are used to indicate which type of value stored in
variable.

C support three classes of data types

1. Primitive (Basic/Fundamental) Data types

2. Non Primitive (Derived) Data types

3. User defined data types.

Fundamental/Basic data types supported by all C compilers.

C provides different qualifiers like signed, unsigned, short and long. By applying different
qualifier to basic data types, we can change the range of data types as per need.
COMPUTER PROGRAMING QUESTION BANK

Q-9 Write a program to enter two numbers from user and find addition of it.
COMPUTER PROGRAMING QUESTION BANK

Q-10 what is String Input & Output?


The function gets () and puts () are used to read and write string respectively. The function gets () is
used to read a string from a keyboard.

The syntax of gets () function is given below.

Void gets(char[]); or void gets(char*)

The function puts () is used to print a string on screen. It automatically move cursor to the beginning
of next line after printing string. The format is given below.

Void puts(char[]) or void puts(char*)

Q-11 what is header file? Give list of header file used in ‘C’ Program.

The C compiler software is bundled with many pre-compiled header files. These are
called system header files. A well-known example is "stdio.h" – a header file included in
almost every C program.
Each of the system header files contains a number of utility functions. These functions are
often called library functions. For example, printf() and scanf() functions, needed for
performing IO operations, are the library functions available in the "stdio.h" header file.

Syntax to Include Header Files in C.

#include <filename.h>

Here is the table that displays some of the header files in C language −
COMPUTER PROGRAMING QUESTION BANK

Q-12 Give difference between syntax error and runtime error.

Q-13 Find errors in following: (1) Int x; (2) float x=”10”; (3) long char b; (4) #define PI=3.14
(1) Capital letter I is not valid so Int is not data type. Valid statement is int x;

(2) Double “” is not allowed in floating value. Valid statement is float x=10;

(3) Long qualifier is not used with char. Valid statement is char b; (4) = is not allowed in macro
declaration. Valid declaration is #define PI 3.14.

Q-14 State why following are invalid variable names.

(1) 1total (2) final result (3) count$ (4) goto

(1) Does not start with digit

(2) Space is not allowed

(3) $ is not allowed


COMPUTER PROGRAMING QUESTION BANK

(4) go to is keyword or reserved word. It is not allowed.

Q-15 Explain Types of Operator in Detail.

C supports rich set of operators. Operators are used to perform various operations on the data or
operands. There are following types of operators.

1) Arithmetic Operators
These operators are used to perform arithmetic operations on data or operands. These operators
are

For example,

if A=15 and B=4, then results of the arithmetic operations are as follows.

A + B = 19

A – B = 11

A * B = 60

A / B = 3 (Division of two integer values gives always integer)

A % B = 3 (Remainder) 17 % 5 = 2, -17 % 5 = -2, 17 % -5 = 2, -17 % -5 = -2.


COMPUTER PROGRAMING QUESTION BANK

2) Relational Operators
These operators are used to compare two operands so these operators are also called
comparison operators. These operators are,

For example,

if A=10 and B=5 then results of following operations are

A > B => true

A >= B => true

A < B => false

A <= B => false

A == B => false

A!= B => true.

3) Logical Operators:

These operators are used to combine two or more relational expressions.


COMPUTER PROGRAMING QUESTION BANK

For example, if X=12 and Y=20, then results of following operations are as follows. X>10 &&
Y!=15 => true && true => true.

Here && and || are also called short circuit operators because if results obtained by first
operand then second operand will not be evaluated. For example,

op1 && op2 in this expression, if op1 is false then result is false and op2 is not evaluated. op1 ||
op2 in this expression, if op1 is true the result is true and op2 is not evaluated.

4) Assignment Operators:

These operators are used to assign the value of variable or constant or value of expression
to the variable on left.
Variable = expression;

Some short hand assignment operators are also used in C.

Syntax: Variable op= expression;

Advantages of short hand operators are:  Variable is not repeated  Statement becomes
more concise and faster.
COMPUTER PROGRAMING QUESTION BANK

Q-16 . Write a program to enter total second and separate hours, minutes and seconds
( 60 second= 1 minute and 60 minute=1 hour).
COMPUTER PROGRAMING QUESTION BANK

Q-17 Write a program to swap or interchange two numbers without using third variable.
COMPUTER PROGRAMING QUESTION BANK

Q-18 what is branching and write only types of branching.

 C program is a set of statements which are normally executed sequentially in the order in
which they appear. This happens when no options or no repetitions of certain calculations are
required. But sometimes, we have a number of situations where we may have to change the
order of execution of statements based in certain conditions or repeat a group of statements
until certain specified conditions are met. Whenever the program control breaks the
sequential flow of execution of program and jump to another part of code it is called
branching.
 There are two types of branching. First one is conditional branching and second one is
unconditional branching.
 Branching that depends upon condition it is called conditional branching and branching that
does not depend upon condition it is called unconditional branching
 C language provides such decision making capabilities by supporting following statements.
 1. If statement
 2. If… else statement
 3. If… else if… else statement
 4. Ladder if…else statement
 5. Nested if statement
 6. Switch case statement
 7. Conditional operator statement
 8. Goto statement

Q-19 Write a program to check number is odd


COMPUTER PROGRAMING QUESTION BANK

Q-20 Write a program to check year is leap year or not.


COMPUTER PROGRAMING QUESTION BANK

Q-21 Explain goto statement with suitable example.


C supports goto statement to branch unconditionally from one point to another in the program. It
may not be essential to use goto statement in a highly structured language like C. goto statement
requires a label in order to identify the place where branch is to be made. A label is any valid
identifier and must be followed by a colon. Label can be anywhere in the program either before or
after goto label; statement. Depending on label, there are two types of goto statement. Forward
goto and backward goto.

goto statement breaks the normal sequential execution of the program. If the label: is before the
statement goto label; then loop will be formed. Such a jump is known as backward jump. On the
other hand, if the label: is placed after the goto label; then some statements will be skipped and
jump is known as a forward jump.
COMPUTER PROGRAMING QUESTION BANK

Q-22 Difference between While and Do… While Loop.


COMPUTER PROGRAMING QUESTION BANK

Q-23: Write a program to print even number between given range.

Q-24 : Write a program to print following Pattern.


1

22

333
COMPUTER PROGRAMING QUESTION BANK

4444

Q-25 Example 6: Write a program to print following Pattern.

1234

123

12

1
COMPUTER PROGRAMING QUESTION BANK

You might also like