Saturday, August 29, 2020

FYBCS C -Programming Assignment 1

 FYBCS C -Programming Assignment 1 

Problem Solving using Pseudo code and Flowchart, Simple programs, Understanding errors and error handling.

Pseudocode :- 

Definition: Pseudocode is an informal way of programming description that does not require any strict programming language syntax or underlying technology considerations. It is used for creating an outline or a rough draft of a program. Pseudocode summarizes a program’s flow, but excludes underlying details. System designers write pseudocode to ensure that programmers understand a software project's requirements and align code accordingly.

Advantages of pseudocode –

• Pseudocode is understood by the programmers of all types.

• it enables the programmer to concentrate only on the algorithm part of the code development.

• It cannot be compiled into an executable program. Example, Java code : if (i < 10) { i++; } pseudocode :if i is less than 10, increment i by 1.

Examples:

1.. If student's grade is greater than or equal to 60

    Print "passed"

else

    Print "failed"
    2. Set total to zero

Set grade counter to one

While grade counter is less than or equal to ten

    Input the next grade

    Add the grade into the total

Set the class average to the total divided by ten

Print the class average.



Algorithm :- 

         Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in more than one programming language.

It must have the following characteristics:

 Clear and Unambiguous: Algorithm should be clear and unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning.

Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined inputs.

Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be well-defined as well.

Finite-ness: The algorithm must be finite, i.e. it should not end up in an infinite loops or similar.

Feasible: The algorithm must be simple, generic and practical, such that it can be executed upon will the available resources. It must not contain some future technology, or anything.

Language Independent: The Algorithm designed must be language-independent, i.e. it must be just plain instructions that can be implemented in any language, and yet the output will be same, as expected.

How to Design an Algorithm?

In order to write an algorithm, following things are needed as a pre-requisite:

 The problem that is to be solved by this algorithm.

The constraints of the problem that must be considered while solving the problem.

The input to be taken to solve the problem.

The output to be expected when the problem the is solved.

The solution to this problem, in the given constraints.

Examples:- 

Problem Definition: Write an algorithm to add given two numbers.

Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Total = A+B.
Step 4: Display Total.
Step 5: Stop.

Problem Definition: Write an algorithm for Subtracting two Numbers.

Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Answer = A - B.
Step 4: Display Answer.
Step 5: Stop.




Flow Charts : 
        Flowchart is a diagrammatic representation of sequence of logical steps of a program. Flowcharts use simple geometric shapes to depict processes and arrows to show relationships and process/data flow.























These are some points to keep in mind while developing a flowchart −

  1.  Flowchart can have only one start and one stop symbol
  2.  On-page connectors are referenced using numbers
  3.  Off-page connectors are referenced using alphabets
  4.  General flow of processes is top to bottom or left to right
  5.  Arrows should not cross each other

Advantages of flowchart:

• Flowchart is an excellent way of communicating the logic of a program.

• Easy and efficient to analyze problem using flowchart.

• During program development cycle, the flowchart plays the role of a blueprint, which makes program development process easier.

• After successful development of a program, it needs continuous timely maintenance during the course of its operation. The flowchart makes program or system maintenance easier.

• It is easy to convert the flowchart into any programming language code.


Examples of Flowchart :- 

Ex. Addition of two numbers 




















Ex.  Convert the temperature of Fahrenheit to Celsius  :











































Ex. To check whether the no is even or odd :- 


No comments:

Post a Comment