Ip Iy Iis Unit 1
Ip Iy Iis Unit 1
UNIT - I
INTRODUCTION TO PROGRAMMING AND PROBLEM SOLVING
1.History of Computers or Generation of Computers?.
History of computers can be understood by looking into five generations. With each new
generation of computers, there had been advancement in computer technology.
Each generation of computer is characterized by a major technological development.
First Generation (1942–1955)
The first generation (1946-1959) computers were slow, huge and expensive. In these
computers, vacuum tubes were used as the basic components of CPU and memory. These
computers were mainly depended on batch operating system and punch cards. Magnetic
tape and paper tape were used as output and input devices in this generation.
Some of the popular first generation computers are:
o ENIAC ( Electronic Numerical Integrator and Computer)
o EDVAC ( Electronic Discrete Variable Automatic Computer)
o UNIVACI( Universal Automatic Computer)
o IBM-701
o IBM-650
Second Generation (1955–1964)
The second generation (1959-1965) was the era of the transistor computers. These
computers used transistors which were cheap, compact and consuming less power; it made
transistor computers faster than the first generation computers.
In this generation, magnetic cores were used as the primary memory and magnetic disc and
tapes were used as the secondary storage. Assembly language and programming languages
like COBOL and FORTRAN, and Batch processing and multiprogramming operating systems
were used in these computers.
PROGRAMMING LANGUAGES
Machine Level Language: Machine language was used to program the first stored program
computer systems. This is the lowest level of programming language and is the only
language that a computer understands. All the commands and data values are expressed
using 0s and 1s.
Assembly Level Language: Assembly languages are symbolic programming languages that
use symbolic notations to represent machine language instructions. Assembly language
developed in the mid-1950s was a great leap forward. It used symbolic codes, also known as
“mnemonic” codes. Examples of these codes include ADD for add, CMP for compare, and
MUL for multiply.
High Level Language: high-level languages were specifically designed to serve a specific
purpose (such as controlling industrial robots or creating graphics), whereas other languages
were flexible and considered to be general purpose. Example of general purpose high-level
languages such as BASIC, FORTRAN, Pascal, COBOL, C++, or Java.
2.Decision: Decision statements are used when the outcome of the process depends on some
condition.
The general form of the if construct is
if condition then process
Example
int var; // variable definition
var = 10; // initialization
or
int var = 10; // variable declaration and definition
C Variable Types
The C variables can be classified into the following types:
1. Local Variables
2. Global Variables
3. Static Variables
Local Variables in C:
A Local variable in C is a variable that is declared inside a function or a block of code. Its
scope is limited to the block or function in which it is declared.
Example of Local Variable in C
// C program to declare and print local variable inside a
// function.
#include <stdio.h>
void function()
{
int x = 10; // local variable
printf("%d", x);
}
int main()
{
function();
}
A Global variable in C is a variable that is declared outside the function or a block of code.
Its scope is the whole program i.e. we can access the global variable anywhere in the C
program after it is declared.
Example of Global Variable in C
// C program to demonstrate use of global variable
#include <stdio.h>
int x = 20; // global variable
void function1() { printf("Function 1: %d\n", x); }
void function2() { printf("Function 2: %d\n", x); }
int main()
{
function1();
function2();
return 0;
}
Static Variables in C:
A static variable in C is a variable that is defined using the static keyword. It can be
defined only once in a C program and its scope depends upon the region where it is
declared (can be global or local).
The default value of static variables is zero.
Example of Static Variable in C
// C program to demonstrate use of static variable
#include <stdio.h>
void function()
{
int x = 20; // local variable
static int y = 30; // static variable
x = x + 10;
y = y + 10;
printf("\tLocal: %d\n\tStatic: %d\n", x, y);
}
int main()
{
printf("First Call\n");
function();
printf("Second Call\n");
function();
printf("Third Call\n");
function();
return 0;
}
float x;
int y = 3;
x = y;
Now, x = 3.0,
• Type casting is also known as forced conversion. It is done when the value of a higher data
type has to be converted in to the value of a lower data type. For example, we need to
explicitly type cast an integer variable into a floating point variable.
List out all the solution that you find. Don’t focus on the quality of the solution
Generate the maximum number of solution as you can without considering the
quality of the solution
Step 3: Evaluate Alternatives
After generating the maximum solution, Remove the undesired solutions.
Step 4: Decide a Solution
After filtering all the solution, you have the best solution only. Then choose on of the best
solution and make a decision to make it as a perfect solution.
Step 5: Implement a Solution:
After getting the best solution, Implement that solution to solve a problem.
Step 6: Evaluate the result
Algorithm Approach:
Algorithm is the set of rules that define how particular problem can be solved in finite
number of steps. Any good algorithm must have following characteristics
Advantages of Algorithms:
Disadvantage of Algorithms:
1. It is time consuming
2. Difficult to show branching and looping statement
3. Large problems are difficult to implement
Time Complexity:
Time complexity is a type of computational complexity that describes the time required to
execute an algorithm. The time complexity of an algorithm is the amount of time it takes for
each statement to complete. As a result, it is highly dependent on the size of the processed
data. It also aids in defining an algorithm's effectiveness and evaluating its performance.
Space Complexity:
Function definition section: Used to define functions which are to be called from main().