Skip to main content

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.

Example:
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.

#include<stdio.h>
main( )
{
int n;
unsigned long int fact =1;
ReadAgain:     /* first label to transfer the control */
printf("Enter a number:");
scanf("%d", &n);
if(n<0)
{
printf("Negative number \n");
goto ReadAgain;    /* Control transferred */
}

Repeat:      /* second label to transfer the control  */
fact = fact*n;
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.

Comments

Popular posts from this blog

difference between structure and union in C Language

In c language article we will see the difference between union and structure. Both are the user define datatype in c language. See the table which is mentioned below: ASP.NET Video Tutorial Series Structure Union1.The keywordstruct is used to define a structure 1. The keyword union is used to define a union. 2. When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum ofsizes of its members. The smaller members may end with unused slack bytes. 2. When a variable is associated with a union, thecompiler allocates thememory by considering the size of the largest memory. So, size of union is equal to the size of largest member. 3. Each member within a structure is assigned unique storage area of location. 3. Memory allocated is shared by individual members of union. 4. The address of each member will be in ascending order This indicates that memory for each member will start at different offset v…

Difference between Linear search and Binary Search in c language

SQL Video Channel : Download all SQL Video



Binary Search Linear Search Works only on sorted items. such as  1,2,3,4,5,6  etc
Works on sorted as well as unsorted items. 12,4,5,3,2,1 etc Very efficient if the items are sorted Very efficient if the items are less and present in the beginning of the list. such as Suppose your list items are : 12,3,4,5,1 and you want to search 12 number then you get beginning in the list. Works well with arrays and not on linked lists. Works with arrays and linked lists.
Number of comparisons are less More number of comparisons are required if the items are present in the later part of the array or its elements are more.

Memory representation of Linked List Data Structures in C Language

Memory representation of Linked List

             In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.

               Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:


      Suppose next node is allocated at an address 506, so the list becomes,



  Suppose next node is allocated with an address with an address 10,s the list become,


The other way to represent the linked list is as shown below:




 In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of next node. The last node …