Computer Programming & Programming Methodology
Computer Programming & Programming Methodology
Unit- 1 Introduction
A computer cannot perform any task of its own and can only understand its own language which is the language of 0’s and 1’s that means binary number system, therefore a computer user has to communicate with a computer using the language which they can understand. The set of instructions to perform a task in the computer that is known as a program and the computer languages in which programs are written is knownas programming language. The person developing or writing programs isknown as “programmer”.
A computer cannot understand the natural language like English. Examples of programming languages are C, C++, C#, Perl, Java, etc.
Introduction to C Programming
History of C Programming
C is a programming language which was developed at “AT & T’s Bell
Laboratory” of USA in 1972.
C was written by Dennis Ritchie, that‟s why he is also called as father of
C Programming language.
C was created for specific purpose that is designing the UNIX Operating
system.
Flowchart and Algorithm
Algorithm and flowchart are two types of tools to explain the process
of a program.
Algorithm:
A step by step method to solve the problem is called algorithm, in other words, an algorithm is a procedure for solving problems.
o Algorithm is a blueprint or plan of our program.
o Features of algorithm:
Proper understanding of the program.
Use of procedures and functions to emphasize
modules.
Choice of variable names.
Documentation of program.
Example:
Write an algorithm to display the sum of two numbers.
Step-1 Start
Step-2 Read two numbers a and b variable.
Step-3 Calculate the sum of a and b and store it in sum variable.
Step-4 Display the value of sum variable.
Step-5 Stop
Advantages:
It is step-wise representation of a solution to a given problem, which makes it easy to understand.
It is not dependent on any programming language, so easy to understand for anyone even without programming knowledge. By using algorithm the problem is broken down into smaller pieces or steps so it is easier for programmer to convert it into an actual program.
Disadvantages:
Writing algorithm takes a long time.
An algorithm is not a computer program, it is rather a
concept of how a program should be.
Example:
#include<stdio.h>
#include<conio.h>
void main()
{
printf(“ Hello World ”);
getch();
}
Practical: (how to do 1st program in C)
1) Open turbo C, by double click in icon.
2) Go to File menu and select New. Blue screen will be display.
3) Include #include<stdio.h> and #include<conio.h> header file.
4) Write void main()
5) Write your program within main().
6) Save your program by click on File menu and select save option or Press F2 key to save your program.
7) Compile your program by click on Compile menu and select compile option OR press Alt + F9. (If error occurs then solve error at compile time)
8) Run your program by click on Run menu and select Run option OR press Ctrl + F9.
Flowchart:
A flowchart is the graphical or pictorial representation of a problem or program or algorithm with the help of different symbols,shapes and arrows in order to demonstrate a process or a program.
The main purpose of a flowchart is to analyze different processes.
Advantages:
The flowchart is an excellent way of communicating the logic of a program.
It is easy and efficient to analyze problem using flowchart.
During program development cycle, the flowchart plays the role to guide or a blueprint, which makes program development process easier.
It helps the programmer to write the program code.
It is easy to convert the flowchart into any programming language code as it does not use any specific programming language concept.
Disadvantages:
The flowchart can be complex when the logic of a program is quite complicated.
During flowchart is a time consuming task
Difficult to alter the flowchart, sometimes the designer needs to redraw the complete flowchart to change the logic of the flowchart or to alter the flowchart.
It is quite tedious task to develop a flowchart as it requires special tools to draw the necessary symbols. Practical Programs:
Program-1 Write a Program to add two numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
int b;
int sum;
a=10;
b=5;
sum=a + b;
printf("Value of sum is %d",sum);
getch();
}
Program-2 Write a Program to Subtract Two numbers
#include<stdio.h>
#include<conio.h>
void main()
{
float a;
float b;
float sub;
a=10.5;
b=5.2;
sub=a - b;
printf("subtraction is %f",sub);
getch();
}
Program-3 Write a program to divide two numbers
#include<stdio.h>
#include<conio.h>
void main()
{
float a;
float b;
float div;
clrscr();
a=10;
b=3;
div=a / b;
printf("division is %f",div);
getch();
}
Structure Programming
In a structure programming, the program is divided into small parts or
functions and each part performs a specific job. The main importance is on
functions rather than data.
Structured Programming Constructs:
1. Sequence Control Structure ( Sequence Logic Or Sequence
Flow)
2. Selection Control Structure (Selection Logic Or Conditional
Flow)
3. Repetition Control Structure (Iteration Logic Or Repetitive
Flow)
1. Sequence Control Structure (Sequence Logic Or Sequential
Flow)
If nothing is specified then the instructions are executed in the sequence in which they are written and in it the modules are executed one after the other.
2. Selection Control Structure (Selection Logic Or Conditional
Flow) In it there are various conditions on the basis of which one module is selected out of several given modules. The structures which implement this logic are called conditional structures.
3. Repetition Control Structure (Iteration Logic Or Repetitive
Flow)
In it loops are implemented. Loop is used to implement those statements which are to be repeated again and again until some condition is satisfied. It implements while and for loops. Each of these begins with repeat statement
Comments
Post a Comment