Monday, August 3, 2020

Pseudocode

Pseudocodes are a means to represent an algorithm in a coded form.The specifications used in a pseudocode are syntactically not stringent as in a program code. However, they represent the steps of an algorithm in a coded from which very closely resembles program code. Given a pseudocode,translation of the same into program code is relatively easy. A pseudocode may be considered to be an intermediate code between an algorithm and program code. The pseudocode for the algorithm in below example:-

Pseudocode SUMN

{

print "Enter a value for the number N: "

scan N

I=1

SUM = 0

while I <= N

{

SUM = SUM+I

I=I+1

}

print "The sum is: ",SUM

}  

It should be noted that a pseudocode is slightly more cryptic compared to an algorithm and is closer in form to a C program code. The C code for the pseudocode shown here would be as follows :-

#include<stdio.h>

Main()

{

Int I,SUM,N;

Printf(“\n Enter a value for the number N:”);

Scanf(“%d”, &N);

While(I <= N)

{

Sum=Sum+I;

I=I+1;

}

Printf(“\ The sum is: %d” , SUM);

}

A quick comparison between the pseudocode and the corresponding program using the C language shows that function names such as ‘printf’ and ‘scanf’ have replaced pseudocodes such as ‘print’ and ‘scan’. ‘print’ and ‘scan’ are codes would not be understood by the C compiler or the machine. Nevertheless, they are still in an encoded form. It is worth nothing that the statements in the C program are syntactically bound. However, such restrictions are not to be found in a pseudocode. 

No comments:

Post a Comment

Detail of Software and Hardware

  Topic   There are available only two things in computer system one is software and another is hardware.   Both is opposite of each other...