You are on page 1of 8

HOMEWORK-1

FOUNDATIONS OF COMPUTING
PART-A

Q1. Draw a flowchart to produce a printed list of all the students over the
age of 20 in a class .The input records contains the name and age of
students. Assume a sentinel value of 99 for the age field of the trailer
record.

Ans. Flowchart to print names of all the students above the age of 20 in a class

START

INPUT NAME, AGE

READ NAME, AGE

IS
AGE>20
&&
AGE<=
99

DO NOT PRINT THE


PRINT THE NAME NAME

PRINT ALL THE


NAMES HAVING
AGE ABOVE 20 AND
BELOW 99

STOP

STOP
Q2. Write a algorithm for multiplication table for an integer?

Ans. An algorithm is a logical sequence of discrete steps that describe a complete


solution to a given problem in a finite amount of time.

integer number, increment, multiple;


print ‘enter the number’;
read number;
while (increment<=required multiple)
{
output=number*multiple;
increment;
}
print ‘output’;
}

Q3. Each paper in a set of examination papers includes a grade of A, B, C, D


or E. A count is to be of how many papers have grade of A and how
many have grade of E. The total of both types have to be printed at the
end. Assume 50 as sentinel value. Write a Pseudo Code to perform this
function.

Ans.
1. Enter the grade.
2. Read the grade.
3. Scan and count paper with grade A, A=i;
4. Scan and count paper with grade E, E=j;
5. Add count of A and B, n=i+j;
6. Print the total count of A and B, print n;
7. End.
Q4. Company X sells merchandise to wholesale and outlets .Wholesale
customers receives a 5% discount on all orders. The company also
encourages both wholesale and retail customers to pay the cash on
delivery by offering a 3% discount for this method of payment .Another
2% discount is given on orders of 500 or more units’. Each column
represents a certain type of order? Draw the decision table?

Ans.
New wholesale Y Y Y N N Y
order
Cash on delivery N Y Y Y N N
500 or more units N N Y Y Y Y

5% discount X X X X
3% discount X X X
2% discount X X X X

PART-B

Q5. How a Source Program converted to an executable program in C?

Ans. First a file is created in which the program is written. The program is written
and if needed edited under the editor. After editing the file is saved. The program
which was entered into the file is called source program. When the program is
ready for compilation the instructions in the program are translated into suitable
execution form by the compiler. After the translation the program is stored in
another file and it is called object code. Now the object code is linked. Linking is
the process of putting together other program files and functions that are required
by the program. After compiling and linking the program the program is called
executable object code and saved as a executable file with file extension ‘.exe’. this
whole process is done with the help of compiler.

Q6. Write down the basic structure of c program. And draw the flow chart
for same? Also elaborate the each section?

Ans. // my first program in C

#include <stdio.h>
#include <conio.h>

void main ()
{
printf ("Hello World!");
getch();
}

// my first program in C (DOCUMENTATION SECTION)


This is a comment line. All the lines beginning with two slash signs (//) are
considered comments and do not have any effect on the behavior of the
program. They can be used by the programmer to include short explanations
or observations within the source itself. In this case, the line is a brief
description of what our program does.

#include <stdio.h> (LINK SECTION)


Sentences that begin with a pound sign (#) are directives for the
preprocessor. They are not executable code lines but indications for the
compiler. In this case the sentence #include <stdio.h> tells the compiler's
preprocessor to include the stdio standard header file. This specific file
includes the declarations of the basic standard input-output library in C, and
it is included because its functionality is used later in the program.

void main () (MAIN() FUNCTION SECTION)


This line corresponds to the beginning of the main function declaration.
The main function is the point where all C programs begin their execution. It
is independent of whether it is at the beginning, at the end or in the middle
of the code - its content is always the first to be executed when a program
starts. In addition, for that same reason, it is essential that all C programs
have a main function. Main is followed by a pair of parenthesis () because it
is a function. In C all functions are followed by a pair of parenthesis () that,
optionally, can include arguments within them.

printf ("Hello World"); (EXECUTABLE PART)


This instruction does the most important thing in this program. printf is the
standard output stream in C. Semicolon character (;) at the end signifies the
end of the instruction and must be included after every instruction in any C
program.

getch ();
The return instruction causes the main() function finish and return the code
that the instruction is followed by. This it is most usual way to terminate a
program that has not found any errors during its execution.

Documentation section

Link section

Definition section

Global declaration section

Declaration part

Executabl
e part

end

Q7. Why do we use qualifiers with data types and elaborate each qualifier
with example?

Ans. Basic data types in C i.e. char, float, int, double has different range of values
and different storage size. In order to have some control over the range of numbers
and storage space, c has different types of qualifiers i.e. short, long, signed and
unsigned. They can be used to stop the wastage of memory. If only 8 bits of
memory is required qualifier ‘short’ can be used with a data type instead of using
the regular data type which would consume 16 bits of memory. Similarly, if more
memory is required than qualifier ‘long’ can be used.
e.g.
1). Data type ‘char’
a). signed char- 8 bits from -128 to 127
b). unsigned char- 8 bits from 0 to 255

2). Data type ‘int’


a). signed int- 16 bits from -32768 to 32767
b). unsigned int- 16 bits from 0 to 65535
c). signed short int- 8 bits from -128 to 127
d). unsigned short int- 8 bits from 0 to 255
e). signed long int- 32 bits from -2147483648 to 2147483647
f). unsigned long int- 32 bits from0 to 4294967295

3). Data type ‘float’- 32 bits from 3.4E –38 to 3.4E +38
4). Data type ‘double’- 64 bits from 1.7E -308 to 1.7E +308
a). long double- 80 bits from 3.4E -4932 to 1.1E +4932

Q8. Differentiate between the following


(a) Unary and Ternary operator.
Ans.
Unary operator Ternary operator
a).The unary operators take one a).Only one ternary operator, ?:,
operand and use either prefix exists; it takes three operands and
notation (such as –-counter) or uses infix notation (condition? intX:
postfix notation (such as counter+ intY).
+).
b).Acts on single operand and b).Acts on three operands and
produces a new value. produces a new value.

(b) Assignment and Equal To operator.


Ans.
Assignment operator Equal to operator
a). It is represented as ‘=’. a). It is represented as ‘==’.
b). It falls under the category of b). it falls under the category of
assignment operators. relational operators.
c). assignment operator is used to c). equal to operator is used to
assign a certain value to a variable. equate two variables.
e.g. int a=12; e.g. if (a==b)
here it shows that variable a has here it shows that in order to satisfy
been given a value 12. the condition variable a should be
equal to variable b.

(c) Expression and statement.


Ans.
Expression Statement
a).Anything legally said in a spot a).A command to the computer
where a value is required. Typically about what to do next.
composed of literals, variables,
operators, functions.
b). An expression consists of one or b).The smallest independent unit in
more operands and usually an a C program. It is analogous to a
operator. Expressions are evaluated sentence in a natural language.
to produce a result. Statements in C generally end in
semicolons.
e.g. my_function() e.g. my_function();

(d) Identifiers and Keywords.


Ans.
Identifiers Keywords
a). identifiers refer to the names of a).keywords serve as basic building
variables, functions & arrays. blocks for program statement.
b). they are user-defined and consist b). all keywords have fixed
of letters and digits. meanings and these cannot be
c). both uppercase and lowercase changed.
are used for them but first character c). all the keywords are written in
should be a letter. lowercase only.
e.g. Area, Sum, Chaman etc. e.g. int, float, enum, break etc.

(e) Signed and Unsigned integers


Ans.
Signed integers Unsigned integers
a). signed integers use one bit for a). unsigned integers use all the bits
sign and 15 bits for the magnitude for the magnitude of the number.
of the numbers.
b). as one bit is for sign they can be b). unsigned integers are always
positive as well as negative. positive.
c).their range is from -32768 to c). their range is from 0 to 65535
32767.

You might also like