0% found this document useful (0 votes)
2 views26 pages

Chapter 2

Chapter 2 discusses the evolution of major programming languages from Zuse's Plankalkül in 1945 to modern languages like Java and C#. It highlights significant languages and their features, including Fortran, Lisp, COBOL, and the introduction of object-oriented programming with Simula 67. The chapter emphasizes the impact of design considerations such as typing systems and programming paradigms on the development of these languages.

Uploaded by

barkatzaidi460
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views26 pages

Chapter 2

Chapter 2 discusses the evolution of major programming languages from Zuse's Plankalkül in 1945 to modern languages like Java and C#. It highlights significant languages and their features, including Fortran, Lisp, COBOL, and the introduction of object-oriented programming with Simula 67. The chapter emphasizes the impact of design considerations such as typing systems and programming paradigms on the development of these languages.

Uploaded by

barkatzaidi460
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 2: Evolution of Major Programming Languages

1. Zuse's Plankalkül (1945)

• Developed by: Konrad Zuse.


• Significance: First high-level programming language.
• Key Features:
o Data types: Simple (bit) and structured (arrays, records).
o Iterations: Implemented using looping constructs and the Fin command.
o Assertions: Statements to define relationships between variables.

2. Early Programming Systems and Languages

Short Code (1949)

• Developer: John Mauchly.


• Type: Interpreted language for the UNIVAC I.
• Key Features:
o Used mathematical symbols instead of machine code.
o Extremely slow (~50x slower than machine language).
o Called automatic programming because it converted mathematical expressions
directly into machine-level operations.

Speedcoding (1954)

• Developer: John Backus for IBM 701.


• Key Features:
o Added floating-point arithmetic and basic functions like square root and sine.
o Purpose: Overcame the lack of floating-point hardware and automatic address
incrementation in early computers.

A-0, A-1, A-2 Systems (1951-1953)

• Developed by: Grace Hopper and her team at UNIVAC.


• Key Features:
o First compiler to convert symbolic code to machine code.
o Allowed programmers to link together pre-written subroutines.

3. The IBM 704 and Fortran

Fortran I (1957)

• Developed by: John Backus and his team at IBM.


• Purpose: Scientific computing with a focus on efficiency.
• Key Features:
o Introduced DO loops and IF statements for control structures.
o Implicit typing: Variables starting with I-N were integers, others were floating-point.
o Focused on generating efficient machine code.

Fortran II (1958)

• Introduced independent compilation of subroutines, making it more modular.

Fortran 90 and Beyond

• Fortran 90: Added dynamic arrays, recursion, and better control structures.
• Fortran 2003: Introduced object-oriented programming features.

4. Functional Programming: Lisp (1958)

• Developed by: John McCarthy at MIT.


• Key Features:
o Focus on symbolic computation (list processing).
o Only two data types: atoms and lists.
o Used recursion instead of iteration.
o Evolution: Lisp started as purely functional but added imperative features for
practical applications.

Descendants:

• Scheme: Smaller, simpler version of Lisp with static scoping.


• Common Lisp: Larger, more complex, used in AI research.

5. ALGOL 60 (1960)

• Developed by: GAMM and ACM committees.


• Significance: Major influence on modern programming languages.
• Key Features:
o Introduced block structure (local variable scopes).
o Allowed recursive subprograms.
o Parameter passing by value and by name.
• Issues: Limited adoption due to lack of standardized I/O, and complexity of pass-by-name
mechanism.

6. COBOL (1960s)

• Developed for: Business applications, led by Grace Hopper.


• Key Features:
o English-like syntax to be readable by non-programmers.
o Hierarchical data structures (records).
o Allowed long identifiers (up to 30 characters) for readability.
o Widely adopted in business and government (due to US Department of Defense
mandate).

7. Basic (1964)

• Developed by: John Kemeny and Thomas Kurtz.


• Purpose: Simple language for non-science students to use on time-sharing systems.
• Key Features:
o Easy syntax and fast feedback through time-sharing.
o Became popular in universities for teaching programming.

8. PL/I (1960s)

• Developed by: IBM.


• Purpose: Unified language for both business and scientific applications.
• Key Features:
o Combined features of COBOL and Fortran.
o Provided multitasking and exception handling.
o Aimed to be a “universal” language but didn’t gain the expected popularity.

9. Object-Oriented Programming: Simula 67 (1967)

• Developed by: Ole-Johan Dahl and Kristen Nygaard.


• Significance: First object-oriented programming language.
• Key Features:
o Introduced concepts of classes, objects, and inheritance.
o Used for simulation but influenced many modern languages (e.g., C++, Java).

10. Evolution of Major Languages (Timeline)

Year Language Key Feature Developer(s)

1945 Plankalkül First high-level programming language Konrad Zuse

1957 Fortran First compiled high-level language John Backus

1958 Lisp First functional programming language John McCarthy

1960 ALGOL 60 Block structure, recursion GAMM, ACM committee


Year Language Key Feature Developer(s)

1964 BASIC Easy-to-use language for students Kemeny, Kurtz

1967 Simula 67 First object-oriented programming language Dahl, Nygaard

1972 C General-purpose programming language Dennis Ritchie

1995 Java Platform-independent, object-oriented James Gosling

2000 C# Object-oriented language for .NET framework Microsoft

11. Notable Programming Exercises

Quicksort Algorithm

• Recursion Example:
o Quicksort divides the array into sub-arrays recursively and sorts each part.
o Python implementation using recursion is simple and follows a divide-and-conquer
strategy.
• Non-Recursion Example:
o Implementing Quicksort iteratively requires using a stack to simulate recursive
behavior.

Matrix Multiplication

• For loops (Counting loops):


o Standard matrix multiplication uses nested for loops to compute the product of two
matrices.
o Each element in the resulting matrix is calculated as the sum of the products of
corresponding row and column elements.
• While loops (Logical loops):
o Matrix multiplication can also be performed using while loops to achieve the same
result, with careful tracking of loop variables.

12. Language Design Considerations

Orthogonality in Language Design

• Orthogonality refers to the independence of language features, meaning that the use of one
feature does not affect the functionality of another. This makes programming languages
easier to learn and use.

Typing Systems
• Static Typing (e.g., Fortran, C): Data types are checked at compile-time, which catches errors
early.
• Dynamic Typing (e.g., Python, JavaScript): Types are checked at runtime, offering flexibility
but with the risk of runtime errors.

Imperative vs. Functional Programming

• Imperative: Focuses on how to achieve a task (e.g., C, Java).


• Functional: Focuses on what should be achieved, using mathematical functions (e.g., Lisp,
Haskell).

Conclusion

Chapter 2 explores the evolution of major programming languages, showcasing how early
languages like Fortran and COBOL laid the foundation for modern programming paradigms
like object-oriented and functional programming. The chapter also highlights the importance
of language design decisions, such as typing systems, orthogonality, and control structures
like recursion and loops.
REVIEW QUESTIONS
1. What is the meaning of Plankalkül? Who developed Plankalkül?
Plankalkül is a programming language developed by Konrad Zuse in the 1940s,
primarily for engineering purposes.
2. What was the simplest data type in Plankalkül?
The simplest data type in Plankalkül was a single bit.
3. How did Plankalkül implement iterations?
Iterations in Plankalkül were implemented using a looping construct with notation
specifying the start, end, and number of iterations.
4. Speedcoding was invented to overcome two significant shortcomings of the
computer hardware of the early 1950s. What were they?
Speedcoding addressed the lack of floating-point hardware and the slow speed of
manual coding for mathematical problems.
5. Why was the technique used by Short Code called automatic programming?
It was called automatic programming because it allowed users to write
mathematical expressions that could automatically be converted to machine code.
6. In what year was IBM 704 introduced?
The IBM 704 was introduced in 1954.
7. Where was Fortran developed? By whom?
Fortran was developed by a team at IBM, led by John Backus, in 1957.
8. Under what environmental constraints was Fortran developed?
Fortran was developed to optimize performance on the IBM 704, which required
efficient programming techniques for the available hardware.
9. How were data types specified for variables in Fortran I?
Data types in Fortran I were specified based on the first letter of the variable name;
for example, variables starting with I-N were integers.
10. What was the most significant feature added to Fortran II to get Fortran IV?
Procedures (subroutines) were the most significant feature added to Fortran II,
which evolved into Fortran IV.
11. What syntactic changes did Fortran 90 include?
Fortran 90 introduced array processing, modules, and free-form source code
syntax.
12. Which version of Fortran was the first to support object-oriented programming?
Fortran 2003 was the first version to support object-oriented programming.
13. Which version of Fortran was the first to have local scopes?
Fortran 77 was the first version to include local scopes in procedures.
14. Why was Fortran list processing language (FLPL) designed and implemented as
an extension to Fortran?
FLPL was designed as an extension to Fortran to handle symbolic data and list
processing operations, which were not part of the original Fortran capabilities.
15. Where was Lisp developed? By whom?
Lisp was developed at MIT by John McCarthy in 1958.
16. In what ways do Scheme and metalanguage (ML) differ from each other?
Scheme is a minimalist version of Lisp with a focus on recursion and functional
programming, while ML emphasizes type inference and pattern matching.
17. What are the features of F# that make it unique?
F# integrates functional programming with .NET, offering type inference,
immutable data structures, and seamless interoperation with object-oriented
programming.
18. What are the goals of the new language developed by GAMM and ACM?
The goals of the GAMM and ACM collaboration in developing a new language
(Algol) were to create a language that would be machine-independent, universal,
and suitable for algorithmic descriptions.
19. In what version of ALGOL did the concept of data type appear?
The concept of data type appeared in ALGOL 60.
20. What were the most important modifications made to ALGOL 58?
The modifications included a more formal syntax definition and the introduction of
block structure.
21. What change did ALGOL provide regarding input and output statements?
ALGOL left input/output (I/O) largely undefined, expecting implementation
differences depending on the hardware.
22. On what programming language was COBOL based?
COBOL was heavily influenced by FLOW-MATIC, a language developed by Grace
Hopper.
23. In what year did the Basic design process begin?
The design process for Basic began in 1963 at Dartmouth College.
24. How does COBOL allow variable names to be truly connotative?
COBOL allows variable names to be long and descriptive, making them connotative
and easier to understand in the context of business applications.
25. What organization was most responsible for the early success of COBOL (in
terms of extent of use)?
The U.S. Department of Defense was responsible for COBOL’s early success by
mandating its use for business applications in government projects.
26. What were the objectives behind developing Basic?
Basic was developed to be an easy-to-learn language for students and non-computer
science majors.
27. Why is Alan Cooper known as “the father of Visual Basic”?
Alan Cooper is known as the father of Visual Basic because he developed the original
prototype, which was later transformed by Microsoft into the Visual Basic
environment.
28. What facilities did PL/I provide?
PL/I combined features of scientific computing and business data processing,
offering structured programming, exception handling, and multitasking.
29. What are the two fundamental characteristics shared by APL and SNOBOL?
Both APL and SNOBOL support powerful string manipulation and flexible data
structures.
30. What features of SIMULA 67 are now important parts of some object-oriented
languages?
SIMULA 67 introduced the concepts of classes, objects, and inheritance, which are
fundamental to object-oriented programming today.
31. What innovation of data structuring was introduced in ALGOL 68 but is often
credited to Pascal?
The record data structure, which allows the grouping of different data types, was
introduced in ALGOL 68.
32. What was the primary deficiency of ALGOL 60?
ALGOL 60’s primary deficiency was its lack of standardized I/O operations, which
made practical use difficult.
33. Which language was used for teaching programming in the 1970s?
Pascal was commonly used for teaching programming in the 1970s.
34. What operators in C were modeled on similar operators in ALGOL 68?
C’s increment (++), decrement (--), and assignment operators (+=, -=) were
modeled after ALGOL 68.
35. Why is C both liked and disliked?
C is liked for its efficiency and control, but disliked for its potential to produce
insecure and error-prone code due to lack of strong type checking.
36. What is a procedural language?
A procedural language is a programming language that is based on the concept of
procedure calls, where tasks are performed using sequences of commands.
37. What are the two kinds of statements that populate a Prolog database?
The two kinds of statements in a Prolog database are facts and rules.
38. What is the primary application area for which Ada was designed?
Ada was designed primarily for real-time and embedded systems in defense and
aerospace applications.
39. What are the concurrent program units of Ada called?
Ada’s concurrent program units are called tasks.
40. What are the different mechanisms in C that show that it was influenced by
ALGOL 68?
C was influenced by ALGOL 68 in its use of block structures, looping constructs,
and operators.
41. Why did Ada 95 lose its popularity?
Ada 95 lost popularity due to its complexity, the rise of other languages like C++
and Java, and poor tool support outside of defense-related industries.
42. What is the meaning of operator overloading in C++?
Operator overloading allows custom behavior to be defined for operators (like + or
*) when applied to user-defined types.
43. What additional feature did the release 3.0 of C++ provide?
C++ 3.0 introduced templates, enabling generic programming.
44. From what language does Objective-C borrow its syntax for method calls?
Objective-C borrows its method call syntax from Smalltalk.
45. What is the primary application for Objective-C?
Objective-C is primarily used for developing macOS and iOS applications.
46. What do the Ada and COBOL languages have in common?
Both Ada and COBOL are known for their strong emphasis on data abstraction and
their focus on business and defense applications.
47. What are threads in Java?
Threads in Java are units of concurrent execution, allowing multiple tasks to run
simultaneously within a program.
48. What characteristic of Java is most evident in JavaScript?
JavaScript shares syntax similarities with Java, but its most evident characteristic is
the use of objects and event-driven programming.
49. How does the typing system of PHP and JavaScript differ from that of Java?
PHP and JavaScript use dynamic typing, while Java uses static typing, meaning
variable types are determined at runtime in PHP/JavaScript and at compile time in
Java.
50. What array structure is included in C# but not in C, C++, or Java?
Multidimensional arrays with flexible rank (e.g., jagged arrays) are a feature of C#
that’s not as flexible in C, C++, or Java.
51. What are the characteristics of Perl’s arrays?
Perl’s arrays are dynamic, meaning their size can change, and they can store
heterogeneous data types.
52. For what application area is JavaScript most widely used?
JavaScript is most widely used for client-side web development to create interactive
websites.
53. What is the relationship between JavaScript and PHP, in terms of their use?
JavaScript is used primarily for client-side scripting, while PHP is used for server-
side scripting.
54. PHP’s primary data structure is a combination of what two data structures from
other languages?
PHP’s primary data structure, the associative array, is a combination of a hash table
and an array.
55. What data structure does Python use in place of arrays?
Python uses lists in place of arrays, which are dynamic and can hold multiple types of
data.
56. What characteristic does Ruby share with Smalltalk?
Ruby shares Smalltalk’s pure object-oriented nature, where everything is treated as
an object.
57. What characteristic of Ruby’s arithmetic operators makes them unique among
those of other languages?
Ruby’s arithmetic operators can be overridden by user-defined methods.
58. What is the similarity between Lua and JavaScript?
Both Lua and JavaScript are designed to be lightweight, embeddable scripting
languages.
59. Is Lua normally compiled, purely interpreted, or impurely interpreted?
Lua is typically impurely interpreted, meaning it’s interpreted but can be compiled
to bytecode for performance.
60. What deficiency of the switch statement of C is addressed with the changes made
by C# to that statement?
C# allows fallthrough prevention in switch statements by requiring explicit action,
addressing C’s ambiguity.
61. What is the primary platform on which C# is used?
C# is primarily used on the .NET platform for Windows applications.
62. What are the inputs to an XSLT processor?
The inputs to an XSLT processor are XML documents and XSLT stylesheets.
63. What is the output of an XSLT processor?
The output of an XSLT processor is typically transformed XML or HTML.
64. What element of the JSTL is related to a subprogram?
Custom tags in JSTL can be seen as subprograms.
65. To what is a JSP document converted by a JSP processor?
A JSP document is converted into a servlet by the JSP processor.
66. Where are servlets executed?
Servlets are executed on a Java application server.
PROBLEM SET
1. What features of Plankalkül do you think would have had the greatest influence
on Fortran 0 if the Fortran designers had been familiar with Plankalkül?
o Plankalkül’s use of arrays and records (structs) would have influenced
Fortran’s handling of data structures. Its iteration mechanisms and logical
assertions (similar to Java’s) might have encouraged better control flow and
debugging in early Fortran versions.
2. Determine the capabilities of Backus’s 701 Speedcoding system, and compare
them with those of a contemporary programmable hand calculator.
o Speedcoding Capabilities: Backus's Speedcoding system included floating-
point arithmetic, trigonometric functions (like sine and square root), and
automatic address incrementation.
o Comparison: Modern programmable calculators have similar arithmetic
functions but generally lack the ability to handle floating-point numbers as
efficiently as a software system running on a machine like the IBM 701.
Modern calculators, however, excel in user interface and portability.
3. Write a short history of the A-0, A-1, and A-2 systems designed by Grace
Hopper and her associates.
o The A-0 system (1951) was the first compiler designed by Grace Hopper at
UNIVAC. It converted symbolic mathematical code into machine code using
pre-written subroutines stored on tape. A-1 improved on this system by adding
more automation in converting code to machine instructions. A-2 (1953)
allowed for greater flexibility in linking subroutines, and it was one of the first
systems to introduce the concept of compiling high-level instructions into
machine code automatically.
4. Compare the facilities of Fortran 0 with those of the Laning and Zierler system.
o The Laning and Zierler system (1953) was an early algebraic compiler that
supported mathematical expressions, arrays, and transcendental functions.
Fortran 0 was designed for general-purpose scientific computations and
included control structures like the DO loop and IF statement but lacked
error-checking, unlike Laning and Zierler’s system, which had a more robust
structure for arithmetic operations.
5. Which of the three original goals of the ALGOL design committee, in your
opinion, was most difficult to achieve at that time?
o The most difficult goal to achieve was the second one: making a language that
could be easily used for printed publications of algorithms. The syntax and
complexity of programming languages made it challenging to create a
readable format that was both understandable in print and mechanically
translatable.
6. Make an educated guess as to the most common syntax error in Lisp programs.
o The most common syntax error in Lisp programs is likely mismatched
parentheses, since Lisp's code and data are both written using lists
(parentheses).
7. Lisp began as a pure functional language but gradually acquired more and more
imperative features. Why?
o Lisp acquired imperative features to improve practical programming
capabilities, particularly for performance and ease of use in large-scale
software systems. Imperative constructs, such as variables and loops, helped
developers manage side effects and optimize code execution.
8. Describe in detail the three most important reasons, in your opinion, why
ALGOL 60 did not become a very widely used language.
1. Lack of input/output facilities: ALGOL 60 lacked standardized input/output
operations, making it difficult to use in practical applications.
2. Complexity of the pass-by-name parameter passing: This feature was
difficult to understand and implement, leading to confusion among
programmers.
3. Poor support from hardware vendors (especially IBM): IBM’s focus on
Fortran led to less support for ALGOL 60, which limited its adoption.
9. Why, in your opinion, did COBOL allow long identifiers when Fortran and
ALGOL did not?
o COBOL was designed for business applications, where readability and
clarity were more important than the brevity needed for scientific
calculations, which Fortran and ALGOL were designed for.
10. Outline the major motivation of IBM in developing PL/I.
o IBM developed PL/I to create a unified language that combined the
capabilities of both business (COBOL-like) and scientific (Fortran-like)
applications. This was intended to reduce the need for multiple programming
languages and streamline development.
11. Was IBM’s assumption, on which it based its decision to develop PL/I, correct,
given the history of computers and language developments since 1964?
o Partially correct. PL/I succeeded in some business environments but never
gained the universal adoption IBM envisioned. Specialized languages like
COBOL and Fortran continued to dominate their respective fields.
12. Describe, in your own words, the concept of orthogonality in programming
language design.
o Orthogonality in programming languages means that features work
independently from one another, so changes or use of one feature have
minimal unintended effects on others. This simplifies both learning and using
the language.
13. What is the primary reason why PL/I became more widely used than ALGOL
68?
o PL/I was backed by IBM, which had a significant market presence and
provided better support for the language. ALGOL 68 was more complex and
did not have strong industry backing.
14. What are the arguments both for and against the idea of a typeless language?
o For: Typeless languages allow greater flexibility and simpler syntax, making
them easier to write.
o Against: Typeless languages can lead to runtime errors that are harder to
catch compared to statically typed languages, and they make debugging more
difficult.
15. Are there any logic programming languages other than Prolog?
o Yes, other logic programming languages include Datalog and Mercury.
16. What is your opinion of the argument that languages that are too complex are
too dangerous to use, and we should therefore keep all languages small and
simple?
o Complex languages can lead to errors and are harder to maintain, but
keeping languages too simple can limit their expressiveness and usability.
Striking a balance is essential—some complexity is necessary for powerful
features, but excessive complexity can be harmful.
17. Do you think language design by committee is a good idea? Support your
opinion.
o Yes and no. A committee brings diverse perspectives, which can lead to well-
rounded design. However, it can also slow down decision-making and lead to
compromises that hinder the language's coherence and simplicity. A small,
focused team might be more efficient.
18. Languages continually evolve. What sort of restrictions do you think are
appropriate for changes in programming languages? Compare your answers
with the evolution of Fortran.
o Restrictions should ensure backward compatibility, minimize complexity,
and prioritize stability. In Fortran’s evolution, new features were added
gradually without breaking existing programs, which is a good model for
language evolution.
19. Build a table identifying all of the major language developments, together with
when they occurred, in what language they first appeared, and the identities of
the developers.

Year Language Feature Developer(s)


1945 Plankalkül First high-level language Konrad Zuse
1957 Fortran First compiled high-level language John Backus
1958 Lisp First functional programming language John McCarthy
1960 ALGOL 60 Block structure, recursion GAMM, ACM committee
1964 BASIC Time-sharing, simple for beginners Kemeny, Kurtz
1968 Simula 67 First object-oriented programming language Dahl, Nygaard
1972 C General-purpose programming Dennis Ritchie
1995 Java Platform-independent, object-oriented James Gosling
2000 C# Integrated .NET language Microsoft

20. There have been some public interchanges between Microsoft and Sun
concerning the design of Microsoft’s J++ and C# and Sun’s Java. Read some of
these documents, which are available on their respective websites, and write an
analysis of the disagreements concerning the delegates.
o You would need to look at primary documents from Microsoft and Sun for a
detailed analysis of their disagreements on Java and J++/C# regarding
delegates. Key issues include compatibility, platform independence (Java)
vs. Windows-centric development (J++/C#), and the implementation of
delegates (event handling and method pointers).
21. In recent years data structures have evolved within scripting languages to
replace traditional arrays. Explain the chronological sequence of these
developments.
o Arrays evolved into associative arrays (hashes/maps) in languages like Perl
and PHP, and later into dynamic lists or dictionaries (Python) and JSON-
like objects (JavaScript). These developments allowed for more flexibility
and ease of use in manipulating data.
22. Explain two reasons why pure interpretation is an acceptable implementation
method for several recent scripting languages.
o 1. Ease of development: Interpreted languages allow immediate execution
without compilation, which is faster for rapid prototyping.
o 2. Portability: Interpreted languages can run on multiple platforms without
needing to recompile, making them suitable for web scripting.
23. Why, in your opinion, do new scripting languages appear more frequently than
new compiled languages?
o Scripting languages are easier to develop, adapt to specific use cases, and are
often designed for specific environments (e.g., web development). Their
interpretation and dynamic typing allow for faster innovation compared to
compiled languages.
24. Give a brief general description of a markup-programming hybrid language.
o A markup-programming hybrid language combines markup (like HTML or
XML) with programming constructs (like loops, conditionals, and
variables). An example is PHP, which integrates HTML and scripting. Hybrid
languages allow dynamic content generation within static layouts.
PROGRAMMING EXERCISE
To understand the value of records in a programming language, write a small program in a C-based
language that uses an array of structs that store student information, including name, age, GPA as
a float, and grade level as a string (e.g., “freshmen,” etc.). Also, write the same program in the
same language without using structs.

Exercise 1: Value of Records (Structs) in a Programming Language

With Structs:

#include <stdio.h>

#include <string.h>

// Define a struct to hold student information

struct Student {

char name[50];

int age;

float gpa;

char gradeLevel[20];

};

int main() {

// Create an array of 3 students

struct Student students[3];

// Input data for each student

strcpy(students[0].name, "Alice");

students[0].age = 19;

students[0].gpa = 3.8;

strcpy(students[0].gradeLevel, "Freshman");

strcpy(students[1].name, "Bob");

students[1].age = 20;

students[1].gpa = 3.5;
strcpy(students[1].gradeLevel, "Sophomore");

strcpy(students[2].name, "Charlie");

students[2].age = 21;

students[2].gpa = 3.9;

strcpy(students[2].gradeLevel, "Junior");

// Print out the student information

for (int i = 0; i < 3; i++) {

printf("Name: %s, Age: %d, GPA: %.2f, Grade Level: %s\n",

students[i].name, students[i].age, students[i].gpa, students[i].gradeLevel);

return 0;

}
QUESTION: 02

To understand the value of recursion in a programming language, write a program that implements
quicksort, first using recursion and then with out recursion.

Exercise 2: Value of Recursion – Implementing Quicksort

With Recursion:

#include <stdio.h>

// Function to swap two elements

void swap(int* a, int* b) {

int t = *a;

*a = *b;

*b = t;
}

// Partition function for quicksort

int partition(int arr[], int low, int high) {

int pivot = arr[high];

int i = (low - 1);

for (int j = low; j < high; j++) {

if (arr[j] < pivot) {

i++;

swap(&arr[i], &arr[j]);

swap(&arr[i + 1], &arr[high]);

return (i + 1);

// Recursive quicksort function

void quicksort(int arr[], int low, int high) {

if (low < high) {

int pi = partition(arr, low, high);

quicksort(arr, low, pi - 1);

quicksort(arr, pi + 1, high);

int main() {

int arr[] = {10, 80, 30, 90, 40, 50, 70};

int n = sizeof(arr) / sizeof(arr[0]);

quicksort(arr, 0, n - 1);
printf("Sorted array: ");

for (int i = 0; i < n; i++)

printf("%d ", arr[i]);

printf("\n");

return 0;

WITHOUT RECURSION
#include <stdio.h>

// Function to swap two elements

void swap(int* a, int* b) {

int t = *a;

*a = *b;

*b = t;

// Partition function for quicksort

int partition(int arr[], int low, int high) {

int pivot = arr[high];

int i = (low - 1);

for (int j = low; j < high; j++) {

if (arr[j] < pivot) {

i++;

swap(&arr[i], &arr[j]);

swap(&arr[i + 1], &arr[high]);

return (i + 1);
}

// Iterative quicksort function

void quicksort_iterative(int arr[], int low, int high) {

int stack[high - low + 1];

int top = -1;

stack[++top] = low;

stack[++top] = high;

while (top >= 0) {

high = stack[top--];

low = stack[top--];

int pi = partition(arr, low, high);

if (pi - 1 > low) {

stack[++top] = low;

stack[++top] = pi - 1;

if (pi + 1 < high) {

stack[++top] = pi + 1;

stack[++top] = high;

int main() {

int arr[] = {10, 80, 30, 90, 40, 50, 70};

int n = sizeof(arr) / sizeof(arr[0]);


quicksort_iterative(arr, 0, n - 1);

printf("Sorted array: ");

for (int i = 0; i < n; i++)

printf("%d ", arr[i]);

printf("\n");

return 0;

3. To understand the value of counting loops, write a program that imple ments matrix
multiplication using counting loop constructs. Then write the same program using only logical
loops—for example, while loops.
Using Logical Loops (While loops):

#include <stdio.h>
#define N 3

void matrixMultiply(int A[N][N], int B[N][N], int C[N][N]) {

int i = 0;

while (i < N) {

int j = 0;

while (j < N) {

C[i][j] = 0;

int k = 0;

while (k < N) {

C[i][j] += A[i][k] * B[k][j];

k++;

j++;

i++;

int main() {

int A[N][N] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

int B[N][N] = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};

int C[N][N];

matrixMultiply(A, B, C);

printf("Resulting matrix:\n");

for (int i = 0; i < N; i++) {

for (int j = 0; j < N; j++) {

printf("%d ", C[i][j]);

printf("\n");
}

return 0;

These solutions demonstrate the value of different programming constructs like structs, recursion,
and counting loops. Let me know if you need any further clarifications!

QUESTION 2 IN PYTHON
QUESTION 3 IN PYTHON

You might also like