‘C’ PROGRAMMING Question and Answer
Programming Structure
Ques 1) What do you mean by programming?
Ans: Programming
A precise list of steps which dedicated to achieving a
particular job is known as program. The
set of instructions which guide the
computer to perform specific operations is known as computer programs. The instructions are arranged in
logical sequence and assembled by
the computer programmers. Computer
programming can be considered as engineering process as careful designing, reliability and low cost
are the main requirements. It is considered
to be an art as well as a literary
effort as programmers use their intuition,
personalization, and expertise about the programming
languages while designing computer programs.
Ques 2) Explain structured programming construct.
Or
Que) Write the short notes on the following:
1) Sequence. 2)
Selection
3) Iteration 4) Modular
Or
1) Sequence 2) Selection
Or
Que) Write short notes on: (2017
[05])
Or
Que) What is modular programming? Explain in detail. (2017[05])
Or
Que) What is Iteration programming structure? Explain in brief. (2016[2.5])
Or
Que) Write a short note on Modular Programming structure. (2018[2.5])
Or
Que) Explain selection and iterative programming structure. (2018[05])
Or
Que) Explain the following terms: (2019[05])
1) Sequence 2) Selection 3) Iteration.
Answers:
Structured
Programming Construct/Control
Structures
A structure is a basic
unit of programming logic; each structure is a sequence, selection, or loop.
With these three structures alone, one can diagram any
task, from doubling a number to performing brain surgery. One can diagram each structure
with a specific configuration of flowchart symbols. The various programming structures
are described below:
1) Sequence Programming Structure: A sequential programming structure
is a sequence of instructions that the computer follows in order, one by one, from
top to bottom. This means that the computer will run the code in order, one line
at a time from the top to the bottom of the program. It will start at line l
then
execute line 2 then line 3 and so on till it reaches the last line of the program.
The actions are typically processes and I/O operations.
The Each action contributes something to the next action.
For example,
int x = 5;
int y = 1l;
int z = x *+y:
printf (z);
2) Selection Programming Structure: A selection programming structure
allows the computer to make a selection between alternative conditions (for
example, if this condition exists, do this - if not, do that). The computer first
assesses the condition and then makes a decision about how to proceed. An example
of a selection structure is the if else statement.
The condition is included in the flowchart as shown in figure below:
As shown in above figure, if the
condition is satisfied. statement 2 gets executed otherwise statement 2 is executed.
For example,
x = 2;
while (x < 100)
{ printf(x);
x = x * x;
}
3) Iteration Programming
Structure: Repetition or looping programming structure
instructs the computer to repeat a set of instructions, called a loop, until
some condition is met. Repetition structure include the while, do/while and for
statements.
For example, for checking any number is even or odd.
int n;
printf ("Enter any number (which is to be checked as
even or odd): ");
scanf ("%d", &n);
if (n%2==0) /*test for
even*/
printf ("%d number is even number", n);
else
printf("%d is an odd number", n);
4) Modular Programming Structure: Modular programming is an approach to software development in
which programmer writes separate functions in separate files, compile them, and
perhaps even separately debug them. Then the modules holding one or several
(debugged and working) functions are brought together for the final link/locate
stage.
To initiate modular programming, break the
overall project into separate parts, and develop and debug them separately. Programmers
partition the project very carefully, so the modules can be reused in later programs.
For example, a time given delay routine can be put into a module and
never give attention again. Likewise, interface software to a peripheral (like a stepper motor ) can be put into a
module with all the interface details (e.g., timing, drive pattern) hidden from
other modules
There is a function to read and check the input
data, and another function to do the analysis. Once the data has been read and analysed,
a fourth function has the
task of outputting the team and player rankings.