CT 1 - Solution
CT 1 - Solution
20 Marks
Q 1 Define the following terms (With Examples):-
a. Algorithm
A sequential solution to any problem written in human language is called as
algorithm.
A process that should be followed for solving a specific problem is called
algorithm.
A step by step problem solving procedure for solving a problem in a finite
number of steps is called algorithm.
The algorithm is defined as the finite set of steps, which provide a chain of
actions for solving a definite nature of problem.
Algorithm MULTIPLICATION(Example)
1. START
2. INPUT first number into variable A
3. INPUT second number into variable B
4. COMPUTE C = A * B
5. DISPLAY C
6. END
b. Flowchart
Flowchart represents the solution of a given problem graphically. Pictorial
representation of the logical steps is a flowchart. It is a diagrammatic
representation that shows flow of execution of a program.
Eg:- Flowchart for multiplication
c. Variables
Variable is an entity whose value can be changed during execution of a
program. Actually, the variable names are the names given to locations in
memory (primary memory – which is most commonly RAM).
Eg. int a=4; // here variable name is ‘a’ and 4 is the constant/value.
float b=8.9879; // here variable is ‘b’ and 8.9879 is constant/value.
JES’s
S.N.D. Polytechnic, Yeola. Class Test
Academic Year- 2023-24
Programme: Computer Engineering Course: PIC Course Code: 312303
Q 2Explain the concept of type casting/type conversion with its types and give one
example of each.
In some situations, programmer needs to convert data type of a variable, a
value or an expression temporarily. Process of doing so is called
typecasting. This can be achieved by using following syntax.(new-data-
type)variable/expression/value
Type of type casting
Implicit Type Casting.(Automatic)
Implicit type casting in C is used to convert the data type of
any variable without using the actual value that the variable
holds. It performs the conversions without altering any of the
values which are stored in the data variable. Conversion of
lower data type to higher data type will occur automatically.
Explicit Type Casting.(Manual)
Example:(Implicit example)
int a = 15, b = 2;
float div;
div = a / b;
printf("The result is %f\n", div);
Example:(Explicit example)
int a,b;
float avg;
printf(“Enter two numbers: ”);
scanf(“%d%d”,&a,&b);
avg=(float)(a+b)/2;
- Special operators
Q 4 State the use of printf() and scanf() with suitable example.
Printf()
We use printf( ) function for displaying formatted output. (printf stands for
print-formatted)
Basic syntax of printf( ) function is given below.
int printf(const char *format [, argument, … ]);
This function converts, formats and displays its arguments on the standard
output. It returns number of characters displayed.
The format string can contain following types of objects
– Ordinary characters (they are directly sent to output as they are)
– Escape sequences.
– Control sequence or conversion specification (they are replaced
sequentially by arguments specified after the formats).
Example 1:
printf(“Hello”); printf(“Everybody”);
Scanf():-
We use scanf( ) function for receiving formatted input. (scanf stands for scan-
formatted).
Basic syntax of scanf( ) function is given below.
int scanf(const char *format [, address, … ]);
This function scans input (one character at a time), formats each field
according to corresponding format specifier passed in format string and
stores the resulting value at the given address (in the specified variable).
Example 1:
int a;
printf(“Enter a value: ”);
scanf(“%d”,&a);
JES’s
S.N.D. Polytechnic, Yeola. Class Test
Academic Year- 2023-24
Programme: Computer Engineering Course: PIC Course Code: 312303