📜  结构化和非结构化编程的区别

📅  最后修改于: 2021-09-13 02:30:05             🧑  作者: Mango

结构化编程

  • 结构化编程是一种编程类型,通常将大型或复杂的程序转换为更易于管理的小代码段。
  • 这些小段代码通常被称为大型复杂程序的函数或模块或子程序。
  • 它被称为模块化编程,可以最大限度地减少函数影响另一个函数的机会。

下面是说明结构化编程的程序:

C
// C program to demonstrate the
// structured programming
#include 
 
// Function for addition
int sum(int a, int b)
{
    return a + b;
}
 
// Function for Subtraction
int sub(int a, int b)
{
    return a - b;
}
 
// Driver Code
int main()
{
    // Variable initialisation
    int a = 10, b = 5;
 
    int add, minus;
 
    // Function Call
    add = sum(a, b);
    minus = sub(a, b);
 
    printf("Addition = %d\n", add);
    printf("Subtraction = %d\n", minus);
    return 0;
}


C
// C program to demonstrate the
// unstructured programming
 
#include 
 
// Driver Code
int main()
{
    // Variable initialisation
    int a = 10, b = 5;
    int add, minus;
 
    // Operations performed
    add = a + b;
    minus = a - b;
 
    printf("Addition = %d\n", add);
    printf("Subtraction = %d\n", minus);
    return 0;
}


输出:
Addition = 15
Subtraction = 5

非结构化编程:

  • 非结构化编程是一种通常按顺序执行的编程,即这些程序只是不从任何代码行跳转,每一行都按顺序执行。
  • 它也被称为能够创建车削完成算法的非结构化编程。

下面是说明非结构化编程的程序:

C

// C program to demonstrate the
// unstructured programming
 
#include 
 
// Driver Code
int main()
{
    // Variable initialisation
    int a = 10, b = 5;
    int add, minus;
 
    // Operations performed
    add = a + b;
    minus = a - b;
 
    printf("Addition = %d\n", add);
    printf("Subtraction = %d\n", minus);
    return 0;
}
输出:
Addition = 15
Subtraction = 5

结构化与非结构化编程之间的表格差异:

Structured Programming

Unstructured Programming

It is basically a subset of procedural programs.   It is basically a procedural program. 
In this, programmers are allowed to code a program simply by dividing the program into modules or smaller units. In this, programmers are not allowed code divide programs into small units. Instead, the program should be written as a single continuous block without any breakage.
It is more user-friendly and easy to understand as compared to unstructured programming. It is less user-friendly and little hard to understand as compared to structured programming.
It is easier to learn and follow. It is difficult to learn and follow
Its advantages include reduce complexity, facilitate debugging, increase programmer productivity programs, etc. Its advantages include its speed. 
Such programs can be used for small and medium-scale projects and also for complex projects.  Such programs cannot be used for medium and complex projects. Instead, they can be used for small and easier projects. 
These programs do not allow code duplication. These programs allow code duplication.  
Structured programs use a greater number of data types as compared to unstructured programs. Unstructured programs use a limited number of data types as compared to structured programs.  
It does not use GOTO to control the flow of execution. Instead, it uses loops.   It uses GOTO to control the flow of execution.
It produces readable code. It hardly produces readable code.
It does not provide full freedom to programmers to program as they want.   It provides full freedom to programmers to program as they want.