0% found this document useful (0 votes)
24 views

Ip Iy Iis Unit 1

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

Ip Iy Iis Unit 1

u 1 notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

INTRODUCTION TO PROGRAMMING

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.

Some of the popular second generation computers are:


o IBM 1620
o IBM 7094
o CDC 1604
o CDC 3600
o UNIVAC 1108

Third Generation (1964–1975)


The third generation computers used integrated circuits (ICs) instead of transistors. A single
IC can pack huge number of transistors which increased the power of a computer and
reduced the cost. The computers also became more reliable, efficient and smaller in size.
These generation computers used remote processing, time-sharing, multi programming as
operating system. Also, the high-level programming languages like FORTRON-II TO IV,
COBOL, PASCAL PL/1, ALGOL-68 were used in this generation.

Some of the popular third generation computers are:


o IBM-360 series
o Honeywell-6000 series
o PDP(Personal Data Processor)
o IBM-370/168
o TDC-316

Fourth Generation (1975–1989)


The fourth generation (1971-1980) computers used very large scale integrated (VLSI)
circuits; a chip containing millions of transistors and other circuit elements. These chips
made this generation computers more compact, powerful, fast and affordable. These
generation computers used real time, time sharing and distributed operating system. The
programming languages like C, C++, DBASE were also used in this generation.

Some of the popular fourth generation computers are:


o DEC 10
o STAR 1000
o PDP 11
o CRAY-1(Super Computer)
o CRAY-X-MP(Super Computer)

Fifth Generation (1989–Present)


In fifth generation (1980-till date) computers, the VLSI technology was replaced with ULSI
(Ultra Large Scale Integration). It made possible the production of microprocessor chips with
ten million electronic components. This generation computers used parallel processing
hardware and AI (Artificial Intelligence) software. The programming languages used in this
generation were C, C++, Java, .Net, etc.

Some of the popular fifth generation computers are:


o Desktop
o Laptop
o NoteBook
o UltraBook
o ChromeBook.

2. Basic Organization Of a Computer Or Block Diagram Of a Computer?.


Arithmetic and Logical Unit :
The ALU performs all kinds of calculations, such as arithmetic (add, subtract, multiply,
divide, etc.), comparison (less than, greater than, or equal to), and other operations. The
intermediate results of processing may be stored in the main memory, as they might be
required again. When the processing completes, the final result is then transferred to the
main memory.
Input Unit:
 The input unit consists of one or more input devices like keyboard, mouse, joystick
etc.
 Regardless of the type of the input device used in a computer system, all input
devices perform the following functions.
 Accept the data
 Convert data to computer understandable form.
 Supply converted data for further processing.
Output Unit:
 The output unit of a computer provides information and results of an operation to
the outside world.
 The output unit also converts Binary data to a form that uses can understand.
 The commonly used to output devices are Monitors, Printers, and Plotters.
Memory Unit:
 Memory Unit of the computer holds data and instructions that we enter through the
input unit.
 It is also used to preserve intermediate and final results before they are sent to the
output unit.
The storage can be classified in to a categories namely
1. Primary Memory
2. Secondary Memory
Primary memory stores and provides information very fast but it loses the contents when
we switch off the computer.
Secondary memory stores the data permanently. The program that we want to run on the
computer is first transferred to the primary memory from secondary.
Ex: RAM (Random Access Memory)
ROM (Read Only Memory)
PROM (Programmable Read Only Memory)
EPROM (Erasable Programmable Read Only Memory)
EEPROM (Electrically Erasable Programmable Read Only Memory).
Program Counter: There is a register in a PC (program counter) processor that contains
the address of the next instruction to be executed from memory. It is a 16-bit register and
is also called instruction counter, instruction pointer, and instruction address register
(IAR). PC (program counter) is a digital counter that is needed to execute tasks quickly and
track the current execution point.

3. Introduction to Programming Languages


A programming language is a language specifically designed to express computations that
can be performed by a computer. The term programming language refers to high-level
languages such as BASIC (Beginners’ All-purpose Symbolic Instruction Code), C, C++, COBOL
(Common Business Oriented Language), FORTRAN (Formula Translator), Ada , and Pascal.
Programming Languages are:
1. Machine Level Language
2. Assembly Level Language
3. High Level Language

PROGRAMMING LANGUAGES

Machine Level Assembly Level High level


Language Language Language

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.

4. Basics of a Computer Program (or)


What is an Algorithm? Explain Features of algorithms and write about some more
algorithms.
An algorithm is a procedure for performing some calculation and it must be implemented
using programming languages. An algorithm provides a blueprint to write a program to
solve particular problems. It is an effective procedure for solving a problem in a finite
number of steps.
Characteristics of an algorithm:
 Be precise.
 Be unambiguous.
 Not even a sing instruction must be repeated infinitely.
 After the algorithm gets terminated, the desired result must be obtained.

Control Structures used in Algorithms


An algorithm exhibits three key features
1. Sequence
2. Decision and
3. Repetition

1. Sequence: Each step of the algorithm is executed in the specified order.


Ex 1: Algorithm to add two numbers Step 1 : Input the first number as A
Step 2 : Input the second number as B
Step 3 : Set Sum=A+B
Step 4 : Print Sum
Step 5 : End

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

A decision statement can also be stated as


if condition
then process1
else process2
Ex: Algorithm to find equality of two numbers
Step1: Input the first number as A.
Step2: Input the second number as B.
Step3: If A=B
then print “Equal”
else
print “Not Equal”
Step 4 : End
3.Repetition: Repetition involves executing one or more steps for a number of times until
some condition is true. These are also called as looping statements. It can be
implemented using constructs such as the
 While
 do-while and
 for loops
Example: Algorithm to print the first 10 natural numbers
Step 1 : [Initialize] Set I=0, N=10
Step 2 : Repeat Step while I<=N
Step 3 : Print I
Step 4 : End
2.) What is a Flowchart and explain its significance with an example.
5. Introduction to Compilation and Execution.
Step1: Compile Source Code (Alt + F9):
Compilation is the process of converting high level language instructions into low level
language instructions. We use the shortcut key Alt + F9 to compile a C program in Turbo C.
Whenever we press Alt + F9, the source file is going to be submitted to the Compiler. On
receiving a source file, the compiler first checks for the Errors. If there are any Errors then
compiler returns List of Errors, if there are no errors then the source code is converted into
object code and stores it as file with .obj extension. Then the object code is given to the
Linker. The Linker combines both the object code and specified header file code and
generates an Executable file with .exe extension.
Step2: Executing / Running Executable File (Ctrl + F9) :
After completing compilation successfully, an executable file is created with .exe extension.
The processor can understand this.exe file content so that it can perform the task specified in
the source file.
We use a shortcut key Ctrl + F9 to run a C program. Whenever we press Ctrl + F9, the .exe file
is submitted to the CPU. On receiving .exe file, CPU performs the task according to the
instruction written in the file. The result generated from the execution is placed in a window
called User Screen.
Step3: Check Result (Alt + F5)
After running the program, the result is placed into User Screen. Just we need to open the
User Screen to check the result of the program execution. We use the shortcut key Alt + F5 to
open the User Screen and check the result.
Execution Process of a C Program

6.Explain various types of data types that are available in C Language.


Data Types:
A data type defines a set of values and the operations that can be performed on them.
Every data type item (constant, variable ...etc) in a C – program has a data type associated
with it. C supports several types of data, each of which may be represented differently within
the computer’s memory. There are mainly 4 types of data types used. They are:
Example: int a, b, c;

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;
}

8.Explain Input and Output Operations in C.


Formatting Input/Output:
1. Printf():
• The printf function is used to display information required to the user and also prints the
values of the variables. Its syntax can be given as printf (“conversion string”, variable list);
• The parameter control string is a C string that contains the text that has to be written on
to the standard output device. The prototype of the control string can be given as below
%specifier .
2. Scanf():
 The scanf() is used to read formatted data from the keyboard. The syntax of the
scanf() can be given as,
scanf (“control string”, arg1, arg2, ………….argn);
• The control string specifies the type and format of the data that has to be obtained from
the keyboard and stored in the memory locations pointed by the arguments arg1, arg2,…,
arg n. The prototype of the control string can be give as: %type
• Type is same as specifier in printf()
Example of printf() and scanf():
int num;
char ch, str[10];
printf(“\n Enter the values : “);
scanf("%d %c ", &num, &ch);
printf("\n num = %d \n ch = %c ", num, ch);

9. Explain Type conversion and Type Casting.


• Type conversion and type casting of variables refers to changing a variable of one data
type into another.
• While type conversion is done implicitly, casting has to be done explicitly by the
programmer. Type conversion is done when the expression has variables of different data
types. So to evaluate the expression, the data type is promoted from lower to higher level
where the hierarchy of data types can be given as: double, float, long, int, short and char.
• For example, type conversion is automatically done when we assign an integer value to a
floating point variable. For ex,

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.

float salary = 10000.00;


int sal;
sal = (int) salary;
10. Explain the various of the Problem solving techniques.?
Problem Solving is a scientific technique to discover and implement the answer to a
problem. The computer is the symbol manipulating device that follows the set of
commands known as program.
Program:
Program is the set of instructions which is run by the computer to perform specific task. The
task of developing program is called programming.
Problem Solving Technique:
Sometimes it is not sufficient just to cope with problems. We have to solve that problems.
Most people are involving to solve the problem. These problem are occur while performing
small task or making small decision. So, Here are the some basic steps to solve the problems
Step 1: Identify and Define Problem
Explain you problem clearly as possible as you can.
Step 2: Generate Possible Solutions

 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

1. Input: Specify and require input


2. Output: Solution of any problem
3. Definite: Solution must be clearly defined
4. Finite: Steps must be finite
5. Correct: Correct output must be generated

Advantages of Algorithms:

1. It is the way to sole a problem step-wise so it is easy to understand.


2. It uses definite procedure.
3. It is not dependent with any programming language.
4. Each step has it own meaning so it is easy to debug

Disadvantage of Algorithms:

1. It is time consuming
2. Difficult to show branching and looping statement
3. Large problems are difficult to implement

10. Illustrate of Problem Solving Strategies?

Top-Down Approach is an approach to design algorithms in which a bigger problem is


broken down into smaller parts. Thus, it uses the decomposition approach. This approach is
generally used by structured programming languages such as C, COBOL, FORTRAN.

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:

When an algorithm is run on a computer, it necessitates a certain amount of memory space.


The amount of memory used by a program to execute it is represented by its space
complexity. Because a program requires memory to store input data and temporal values
while running, the space complexity is auxiliary and input space.
Algorithm Complexity
If N is used to represent the size of the input data and X is assumed to represent an
algorithm, then the efficiency of X is mostly influenced by how much time and space it takes
to implement the method.
Time Factor - The number of crucial operations, such as comparisons in a sorting algorithm,
is counted or quantified to determine how much time has passed.
Space Factor - The amount of space is determined or assessed by adding together how
much memory the algorithm can use.
When N is used as the size of the input data, the complexity of an algorithm f(N) gives the
amount of running time and/or storage space required by the method.

12.Discuss the structure of a ‘C’ program.


C is a procedural programming language initially developed by Dennis Ritchie in the year
1972 at Bell Laboratories of AT&T Labs.
A C program contains one or more functions. The statements in a C program are written in a
logical sequence to perform a specific task. Execution of a C program begins at the main ()
function. We can choose any name for the functions. Every program must contain one
function that has its name as main().
The basic structure of C program is as follow:
Document Section: It consists of set of comment lines which include name of a program,
author name, creation date and other information.
Links Section (File): It is used to link the required system libraries or header files to execute
a program.
Definition Section: It is used to define or set values to variables.

Global variable declaration Section: It is used to declare global or public variable.


void main(): Used to start of actual C program. It includes two parts as declaration part and
executable part.
Variable declaration section: Used to declare private variable.
Function declaration section: Used to declare functions of program from which we get
required output. Then, executable statements are placed for execution.

Function definition section: Used to define functions which are to be called from main().

*************** ALL THE BEST


******************

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy