Unstructured technique of programming in C language
Definition : An approach of designing a program simply using series of statements is called unstructured programming.
In such programming technique every task is solved using series of simple statements only. Branching and repetitions are achieved through a 'goto; statement. Jumping to and out of a block of statements is achieved through 'goto' statement. So, a technique using 'goto' statement is called unstructured technique of programming.
Problem: Design a program to find factorial of a number
The program required is to find n!=1*2*3*4.....*(n-1)*n. If negative number is entered a proper message is to be displayed. So, the repetition and branching is achieved in unstructured programming technique using 'goto' statement. The statement 'goto' in C is used to take the control from one point to another irrespective of the location of transfer. It takes control to the specified label.
unsigned long int fact =1;
ReadAgain: /* first label to transfer the control */
printf("Enter a number:");
printf("Negative number \n");
goto ReadAgain; /* Control transferred */
Repeat: /* second label to transfer the control */
fact = fact*n;
if(n>=1) goto Repeat; /* Control transferred to label Repeat */
printf(" The factorial is %lu", fact);
Features of unstructured technique
- Simple statements are used to solve a task.
- The statements used are basic and understandable.
- This type of programming is called liner programming.
- The approach is straight forward.
- To branch from one point to other only a simple 'goto' statement is used.
- Even to repeat a part of the program 'goto' statement is used.
- Every logic of the program is developed using only 'goto' statement.
Merits of unstructured technique
The unstructured technique of programming although having some merits is not at all entertained to design the programs. The merits to just list are:
- The program designed is simple.
- The logic is simple and straight forward.
- Only one statement 'goto' is used for branching as well as looping.
Demerits of unstructured technique
The unstructured technique of programming is very rarely used. It is never entertained because of its demerits. The demerits of the unstructured technique are:
- To follow the logic of the program is very difficult.
- There may be abrupt transfer from one point to another.
- This technique can be applied only to small-scale programs.
- Difficult to keep track the logic of the program.
- Excessive use of 'goto' statements causes confusion in program flow.
- The quality of the program decreases as the number of 'goto' statements increases.
- Program designed using this technique is not clear for the others and also at times to the designer of the program.
- It is difficult for the programmer to understand the logic at the later stage.
- Because of excessive use of 'goto' statements tracing the error is very difficult.
- Testing of program consumes lots of time.
- Redesigning a program is much more difficult.
- Unstructured programs consist of statements that are not grouped for specific tasks.
- The logic of such programs is messy with details and therefore difficult to follow.