In general if we want to get anything done by someone, we have to tell exactly what we want. Same is the case with the computers more so than anything else. Unless we specify what we want exactly in the language it can understand, computer can not do our work. If it does the work, the results may be unpredictable and there is no meaning in blaming the computer for our short comings. Following are the steps you consider before telling the computer:
1. First we have to write down what the computer has to do for us.
2. Next we have to determine what basic materials the computer needs to do that work.
3. Next we have to tell the computer step by step what to do with those basic materials to produce the product we desire. Remember computer does things faster than us. If we give wrong instructions, it will give wrong results faster.
Let us try a program. We write a line saying " My first pascal program".
We are going to use pascal compiler. We write instructions for the computer to print "My first pascal program".
Program follows:
Program program1;
{ This is my first program }
begin
writeln(' My first pascal program ');
readln;
end.
Program program2;
uses crt,graph;
var number1, number2 : integer;
var interest1, interest2 : real;
var name1, name2 : string;
{ This is my second program }
begin
writeln('My second Pascal Program');
readln;
end.
The first line of the program says: Program name is program1. Notice the semi colon. Every statement ends with a semi colon ";".Exception is last statement "end.". It ends with a period '.'.
The second statement is a comment. Comments are enclosed by "{" and "}". Notice we do not put any semicolon. Comments are not compiled by the compiler.
The beginning of a program begins with "begin" and ends with "end.".
In between these two we have to give instructions to the computer.we have two instructions. They are called statements.
First statement is to write a line: "My first pascal program".
Second statement is to go to the next line and wait for my input. If we do not put this statement, the computer writes the line " My first pascal program". The second statement makes the computer wait for our input so that we can see the line. Just press ENTER on the key board and the execution goes to next statement.
The final statement is "end." which states this is the end of the program. The execution is complete.
Summary:Pascal program consists of statements, each specifying a step to be done by the computer. Each statement ends with a semi colon(;). The first statement 'Program' states the name of the program to the computer. The program starts with 'begin' and ends with 'end.'. In between these two we can write statements to the computer.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment