question mark, important, sign-1872665.jpg

SICE COMPUTER STUDENT NOTE

 Programming and Problem Solving through C Language (S1P3)

CHAPTER– 1 [GETTING STARTED WITH C]

What is C?                                       

 

  • C is a programming language developed by AT & T’s Bell Laboratories of USA in 1972. In computing, C is a general-purpose programming languagedeveloped by Dennis Ritchie between 1969 and 1973.
  • C is a structured programming middle level Machine Independent language. It is also a 3rd generation Language. It is one of the most widely used programming languages of all time.
  • It is a programming language which has used for writing codes operating systems like Windows, UNIX, Linux, etc.
  • Mobile device and common consumer device like microwave ovens, washing machine digital camera, etc are working with a microprocessor, an operating system and a program embedded in these devices. These programs are written in C.
  • C is also used to develop the computer games.

History of C

 

  • ALGOL first computer language to use a block structure. It was developed in 1960 by the International Group. It was widely used in Europe.
  • Many of the important ideas of C come from the language BCPL (Basic Combined Programming Language) developed in 1967 by Martin Richards.
  • The influence of BCPL on C proceeded indirectly through the language B, which was written by Ken Thompson in 1970 at Bell Labs.
  • In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of The C Programming Language by Kernighan & Ritchie caused a revolution in the computing world.

 

What is programming language?

 A programming language is a computer language programmers use to develop applications, scripts, or other set of instructions for a computer to execute. Below is a listing of several different programming languages and scripting languages currently listed in our database.

  • ALGOL
  • FORTRAN
  • BASIC
  • BCPL
  • C
  • C++
  • C#
  • COBOL
  • HTML
  • JAVA
  • LOGO
  • Visual Basic
  • Visual FoxPro
  • XML
  • WML
  • PHP
  • SQL
  • Pascal
 

 

  • Applications and Program development

Application and program development involves programs you work on a daily bases. For example, the Internet browser you are using to view this web page is considered a program. If you are interested in writing your own programs you should consider the below languages.

 

 
 
 
  • Artificial Intelligence development

Artificial Intelligence or related fields could involve anything from creating the character interactions in computer games, portions of programs that make the decisions in programs, chatbots, or any other related programs. If you’re interested in writing your own AI you should consider the below languages.

 

 

  • Database development

Database developers create and maintain databases. If you’re interested in creating your own database or maintaining other databases you should consider any of the below languages.

 

 

 

  • Game development

Game development involves the development of computer games or other entertainment software. If you’re interested in writing your own games you should consider the below languages.

 

 

  • Computer drivers or other hardware interface development

Computer drivers and programming hardware interface support is a necessity for computers to operate with the hardware; without it your computer wouldn’t work. If you’re interested in writing your own drivers or software interfaces for hardware devices you should consider the below languages.

 

 

  • Internet and web page development

The Internet and web page development is the essence of the Internet, without developers we would have no Internet. If you’re interested in creating your own web pages, developing Internet applications, or Internet related tasks, you should consider the below languages.

 

 

  • Script development

Although not likely to be a career, knowing how to create and develop scripts to increase your productivity or your company’s can save you countless hours. If you’re interested in developing your own scripts you should consider the below languages.

 

What is program and programmer?

A program is like a recipe. It contains a list of ingredients (called variables) and a list of directions (called statements) that tell the computer what to do with the variables. The variables can represent numeric datatext, or graphical images.

 

In simple words we can say the set of instruction written in a programming language is known as a Program and a person engaged in the activity of program or programming is called a Programmer.

 

What are the types of Language?

A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely.

 

There are two types of programming language:

  1. Low label language
  2. High label language

What is Low label language?

In computer science, a low-level programming language is a programming language that provides little or no abstraction from a computer’s instruction set architecture. Generally this refers to either Machine Code or Assembly Language.

 

The word “low” refers to the small or nonexistent amount of abstraction between the language and machine language; because of this, low-level languages are sometimes described as being “close to the hardware.”

 

Machine code is the only language a microprocessor can process directly without a previous transformation. Currently, programmers almost never write programs directly in machine code, because it requires attention to numerous details which a high-level language would handle automatically, and also requires memorizing or looking up numerical codes for every instruction that is used.

 

Assembly language is not considered a programming language as it has no semantics and no specification, being only a mapping of human readable tokens to op codes. The human readable tokens are assembled directly into machine code on a, usually, one to one basis. The assembly code can also be abstracted to another layer in a similar manner as machine code is abstracted into assembly code.

 

What is High label language?

 A programming language such as CFORTRAN, or Pascal that enables a programmer to write programs that are less independent of a particular type of computer. Such languages are considered high-level because they are closer to human languages.

 

The main advantage of high-level languages over low-level languages is that they are easier to read, write, and maintain. Ultimately, programs written in a high-level language must be translated into machine language by a compiler or interpreter.

 

The high label language is categorized into following types.

 

  1. Procedural
  2. Non Procedural
  3. Functional
  4. Scripting
  5. Structural
  6. Modular
  7. Object Oriented
  8. Pure Objected Oriented

Principal and Technique of Programming

The principles of good programming are closely related to principles of good design and engineering. The programmer should follow the following stapes for good programming.

 

  • Define the Problem
  • Program Design
  • Selection of Algorithm
  • Writing the Programming Code
  • Compiling
  • Debugging
  • Testing
  • Documentation
  • Maintenance

 

Characteristics of good Program

 Programming style consists of three important qualities:

  • Readability
  • Portability
  • Maintainability

Readability

  • You should write the source code or the program in high level language that it is readable to you and to others. This includes aesthetic formatting, meaningful variables names and consistency within and across the source files.

Portability

  • Write the code using high level language so that it is easy to transfer the program to other machines as well. If possible avoid nonstandard features and also use the standard library runtime routines rather than writing your own and thus save time.

Maintainability

  • As you write the program, think about how you might want to change or extend it in future. For example, put data structure definitions in header files where changes will automatically broadcast to all source files that include the header file.

Programming Tools

Programming tools defines that the process to solve a problem. This section is only to understand the program to write the programming code in any programming language. Fallowing are three tools for the C language program.

  1. Algorithm
  2. Flow Chat
  3. Pseudo code

————————

Chapter-2

ALGORITHM, FLOW CHART AND PSEUDO CODE

What is Algorithm?

A set of instruction which describes the steps to be followed to carry out an activity is called an algorithm or procedure for solving a problem. If the algorithm is written in the computer’s programming language then such a set of instruction is called a program.

We can view an algorithm as a way to solve a problem or in other words, as a set of direction, that tell us exactly how to go about for getting the desired result.

In mathematics and computer science, an algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation.

In simple words we can say an algorithm is a set of step-by-step procedures, or a set of rules to follow, for completing a specific task or solving a particular problem

Example:

We can use following steps or actions to reach the office by 10 AM.

Action:

  1. Get ready by 8 AM.
  2. Take breakfast
  3. Board the chartered bus at 9 AM.
  4. Read office at 10 AM.

Definition of algorithms

We can define an algorithm as an order sequence of well-defined and effective operation that, when executed, will always produce the desired result and terminate in a finite amount of time.

An algorithm must always one clearly understood starting point and one or more clearly understood ending points. The starting point should START and ending point should STOP.

What is Flow Chart?

A flowchart is a graphical representation of the sequence of operations in an information system or program. Program flowcharts show the sequence of instructions in a single program or subroutine. Since a flowchart shows the flow of operations in pictorial form, any error in the logic of the procedure can be detected easily.

Flow Chart Symbols

  1. Processing

A processing symbol is used in a flowchart to represent arithmetic and data movement instructions.

  • Flow lines

Flow lines with arrowheads are used to indicate the flow of operation, that is, the exact sequence in which the instructions are to be executed.

  • Decision

The decision symbol is used in a flowchart to indicate a point at which a decision has to be made and a branch to one of two or more alternative points is possible.

Terminal (Begin / End)

This symbol is used to start or end a flowchart.

Input / Output

This symbol is used to denote any kind of input or output.

Connector

If a flowchart becomes very long, the flow lines start crisscrossing at many places that causes confusion and reduces the clarity of the flowchart.

Rules for Writing Flowcharts

  1. First formulate the main line of logic, and then incorporate the details in the flowchart.
  2. Maintain a consistent level of detail for a given flowchart.
  3. Do not give every detail on the flowchart. A reader who is interested in greater details can refer to the program itself.
  4. Words in the flowchart symbols should be common statements and easy to understand.
  5. Be consistent in using names and variables in the flowchart.
  6. Go from left to right and top to bottom in constructing the flowchart.
  7. Keep the flowchart as simple as possible. The crossing of flow lines should be avoided as far as possible.
  8. If a new flowcharting page is needed, it is recommended that the flowchart be broken at an input or output point. Moreover, properly labeled connectors should be used to link the portions of the flowchart on different pages.

Question  for algorithms and flow chart 

  1. Write an algorithm and flow chart to add two Nos.
  2. Write an algorithm and flow chart to add any three Nos.
  3. Write an algorithm and flow chart to subtract any two Nos.
  4. Write an algorithm and flow chart to multiply any two Nos.
  5. Write an algorithm and flow chart to divide any two Nos.
  6. Write an algorithm and flow chart to find the reminder.
  7. Write an algorithm and flow chart to find the square of a No.
  8. Write an algorithm and flow chart to find the power.
  9. Write an algorithm and flow chart to find the average between 4 Nos.
  10. Write an algorithm and flow chart to calculate simple interest.
  11. Write an algorithm and flow chart to find greater among two Nos.  
  12. Write an algorithm and flow chart to find greater among three Nos.
  13. Write an algorithm and flow chart to find greater among four Nos.
  14. Write an algorithm and flow chart to test a No. is +ve or –ve.
  15. Write an algorithm and flow chart to test a No. is Even or Odd
  16. Write an algorithm and flow chart to test pythagorious theorem. 
  17. Write an algorithm and flow chart to test a No. is +ve or –ve.

  1. What is Pseudocode?

Pseudocode (pronounced SOO-doh-kohd) is an outline of a program written in a form that can easily be converted into real programming statements. Pseudocode is an artificial programming language that allows computer programmers to develop logic before executing a particular code. It can be defined as the blueprint of a code, which details a step of actions (or the procedure) and the order in which the steps are to be executed.

Pseudocode is a type of structured English that defines program algorithms. It allows programs to focus on algorithms core logic before setting it in formal programming syntax. Pseudocde is not executable on a computer. Instead, it helps a programmer design code before its actual implementation.

The main purpose of pseudocode is to describe clearly what a code (or program) is supposed to do. It breaks down a code into steps and highlights their sequence of action. Pseudocode allows coders and programmers to dry-run a code to check for errors and inconsistencies before writing it in a programming language.

Purpose

The main purpose of pseudocode is to describe clearly what a code (or program) is supposed to do. It breaks down a code into steps and highlights their sequence of action. Pseudocode allows coders and programmers to dry-run a code to check for errors and inconsistencies before writing it in a programming language.

Rules

Pseudocode is composed of sentences, clauses and words. It follows a structured pattern, with statements written in a sequential order. Pseudocode uses selection statements (if, then and if, then, else), and the initial keyword in each statement needs to be capitalized. It requires one statement per sentence, which need to be indented to show code hierarchy.

Example

M = 10
N = 5

(where M and N are variables)

IF (M >= N) Then

Statement 1

Else

Statement 2

END IF

Statement 3

According to this example, the condition of M>=N is true (since M is 10 and N is 5), and statement 1 will be executed. The execution of statement 3 follows that.

41 thoughts on “Programming and Problem Solving through C Language”

  1. # Write an algorithm find smaller among two Nos.
    1)START
    2)input a,b
    3)if(a<b) then (4) else (5)
    4)print a is smaller go to (6)
    5)print b is smaller go to (6)
    6)STOP

  2. Write an algorithm to find the smaller among two no?
    1/- start
    2/-input a,b
    3/-if(a<b)then(4)else(5)
    4/-print a is smaller go to (6)
    5/-print b is smaller go to (6)
    6/-stop

  3. Write an algorithm to find the smaller amount two numbers
    1/Start
    2/input a,b
    3/if,(a<b)then(4)else(5)
    4/print a is smaller go to (6)
    5/print b is smaller go to (6)
    6/stop

  4. Write an algorithm to find the smaller amount two number.
    1/Start
    2/input a,b
    3/if(a<b) then (4), else (5)
    4/print a is smaller go to (6)
    5/print b is smaller go to (6)
    6/Stop

  5. Write an algorithm to test a No is +ve or -ve.
    1)START
    2)input a
    3)if(a>0) then (4) else(5)
    4)print a is +ve go to (6)
    5)print a is -ve go to (6)
    6)STOP

  6. Write an algorithm to test a no +ve or -ve
    1/- start
    2/-input a,b
    3/-if (a>0) then (4) else(5)
    4/-print a is +ve go to (6)
    5/-print a is -ve go to (6)
    6/-stop

  7. Write an algorithm to test a no is +ve or -ve
    1/start
    2/input a,b
    3/if (a>0) then (4)else (5)
    4/print a is+ve go to (6)
    5/print b is -ve go to(6)
    6/stop

  8. Write an algorithm to text a no is +ve or-ve
    1/start
    2/input a, b
    3/if (a>0) then (4) else (5)
    4/print a is+ve go to (6)
    5/print b is-ve go to (6)
    6/stop

  9. Write an algorithm find greater among three Nos.
    1\ START
    2\ input a,b,c
    3\ if(a>b>c) then (4) then (5) else (6)
    4\print a is greater go to (7)
    5\print b is greater go to (7)
    6\print c is greater go to (7)
    7\ STOP

  10. Write an algorithm find greater among four Nos.
    1\ START
    2\ input a,b,c,d
    3\ if(a>b>c>d) then (4) then (5) then (6)else (7)
    4\ print a is greater go to (8)
    5\ print b is greater go to (8)
    6\ print c is greater go to (8)
    7\ print d is greater go to (8)
    8\ STOP

  11. Write an algorithm test a No. is Even or Odd
    1\ START
    2\ input a
    3\ if(a>0) then (4) else (5)
    4\ print a is Even go to (6)
    5\ print a is Odd go to (6)
    6\ STOP

    1. 1) Start
      2) Input a,b,c
      3) if ((a*a)=(b*b)+(c*c) then (6) else (4)
      4) if ((b*b)=(a*a)+(c*c) then (6) else (5)
      5) if ((c*c)=(b*b)+(a*a) then (6) else (7)
      6) Print “Pythagoras theorem” go to (8)
      7) Print “Not Pythagoras theorem”
      8) Stop

  12. RAJIB KUMAR SAHOO

    # Write an algorithm to prove Pythagoras theorem.

    1) Start
    2) Input a,b,c
    3) if ((a*a)=(b*b)+(c*c)) then (6) else (4)
    4) if ((b*b)=(a*a)+(c*c)) then (6) else (5)
    5) if ((c*c)=(b*b)+(a*a)) then (6) else (7)
    6) Print “Pythagoras theorem” go to (8)
    7) Print “Not Pythagoras theorem”
    8) Stop

  13. RAJIB KUMAR SAHOO

    # Write an Algorithm to test whether 3 sides can from a Triangle or not.

    1) START
    2) Input a,b,c
    3) if (a+b>c)then(4)else(7)
    4) if (b+c>a)then(5)else(7)
    5) if (c+a>b)then(6)else(7)
    6) Print “It is a Triangle ” go to (8)
    7) Print “It is Not a Triangle”
    8) STOP

  14. Write an algorithm to find a no is even or odd.
    1/-Start
    2/-Input a
    3/-If(a%2=0)then (4)else(5)
    4/-Print “a is even No”go to (6)
    5/-Print “a is odd No “go to (6)
    6/-Stop

  15. Write an algorithm test a no even or odd
    1/start
    2/input a
    3/if (a%2)then (4)else (5)
    4/print “a is even no ” go to (6)
    5/print “a is odd no” go to (6)
    6/stop

  16. Write an algorithm test a no even or odd
    1/Start
    2/input a
    3/if (a%2) then (4) else (5)
    4/print “a is even no” go to (6)
    5/print”a is odd no” go to (6)
    6/stop

  17. # Write an algorithm to prove Pythagoras theorem.

    1) Start
    2) Input a,b,c
    3) if (a×a)=(b×b)+(c×c) then (6) else (4)
    4) if (b×b)=(a×a)+(c×c) then (6) else (5)
    5) if (c×c)=(b×b)+(a×a) then (6) else (7)
    6) Print “Pythagoras theorem” go to (8)
    7) Print “Not Pythagoras theorem”
    8) Stop

  18. Write an algorithm to prove Pythagoras theorem.

    1) Start
    2) Input a,b,c
    3) if ((a×a)=(b×b)+(c×c) then (6) else (4)
    4) if ((b×b)=(a×a)+(c×c) then (6) else (5)
    5) if ((c×c)=(b×b)+(a×a) then (6) else (7)
    6) Print “Pythagoras theorem” go to (8)
    7) Print “Not Pythagoras theorem”
    8) Stop

  19. 1) Start
    2) Input a,b,c
    3) if ((a*a)=(b*b)+(c*c) then (6) else (4)
    4) if ((b*b)=(a*a)+(c*c) then (6) else (5)
    5) if ((c*c)=(b*b)+(a*a) then (6) else (7)
    6) Print “Pythagoras theorem” go to (8)
    7) Print “Not Pythagoras theorem”
    8) Stop

  20. Write an algorithm to display all the nos from 1to 10.
    1/start
    2/N=2
    3/print N
    4/N=N+1
    5/if (N<=10) then (3) else (6)
    6/stop

  21. Write an algorithm to display all the nos from 1 to 10 .
    1) start
    2)a=1
    3) print a
    4)a=a+1
    5)if (a<=10) then (3) else (6)
    6)stop

  22. Write an algorithm to display all the nos from 1 to 10 .
    1)Start
    2)a=1
    3)Print a
    4)a=a+1
    5)IF (a<=10)then(3)else(6)
    6)Stop

  23. Write an algorithm to display all the nos from 20 to 50.
    1)Start
    2)P=20
    3) Print P
    4)P=P+1
    5)if(P<=50)then (3)else (6)
    6)Stop

  24. Write an algorithm to display all the nos from 20 to 50 .
    1) start
    2) b=20
    3) print b
    4) b=b+1
    5) if (b<=50) then (3) else (4)
    6) stop

  25. Write an algorithm to display all the nos from 20 to 50.
    1/start
    2/N=1
    3/print N
    4/N=N+1
    5/if (N<=50) then (3) else (4)
    6/stop

  26. # Write an algorithm to display all the Odd Nos. up to 20
    1) START
    2)c=1
    3) print c
    4) c=c+2
    5) if(c<=20) then (3) else (6)
    6) Print "The sum
    7) STOP

  27. # Write an algorithm to display all the Even Nos. from 30 to 100
    1) START
    2)c=30
    3) print c
    4) c=c+2
    5) if(c<=100) then (3) else (6)
    6) Print "The sum
    7) STOP

  28. Write an algorithm to display all the factors of a number
    1) START
    2) Read N
    3) C = 1
    4) if N mod C = 0 then (5) else (6)
    5) Display C
    6) C = C + 1
    7) if C < = N then (4) else (8)
    8) STOP

  29. Write an algorithm to swap or enter change the value of 2nd veriable using 3rd veriable
    1) START
    2) Read ” Enter the value of A “, a
    ” Enter the value of B “, b
    3) c = a
    a= b
    b = c
    4) Display ” The value of A “, a
    ” The value of B “, b
    5) STOP

  30. Write an algorithm to swap or enter change the value of 2nd veriable without 3rd veriable
    1) START
    2) Read ” Enter the value of A “, a
    ” Enter the value of B “, b
    3) a = a + b
    b = a – b
    a = a – b
    4) Display ” The value of A “, a
    ” The value of B “, b
    5) STOP

  31. Write an algorithm to find the revers of a number
    1) START
    2) S = 0
    3) Read N
    4) R = N mod 10
    5) Q = int (N/10)
    6) S =(S × 10) + R
    7) N = Q
    8) if Q ≠ 0 then (4) else (9)
    9) Display S
    10) STOP

  32. Write an algorithm to test a number is pellindru number or not
    1) START
    2) S = 0
    3) Read N
    4) M = N
    5) R = M mod 10
    6) Q = int (M/10)
    7) S = (S × 10) + R
    8) M = Q
    9) if Q ≠ 0 then (5) else (10)
    10) if N= S then (11) else (12)
    11) Display N is pellindru number goto (13)
    12) Display N is not pellindru number
    13) STOP

  33. Write an algorithm to test a number Armstrong number or not
    1) START
    2) S = 0
    3) Read N
    4) M = N
    5) R = M mod 10
    6) Q = int ( m/10)
    7) S = S + R^3
    8) M = Q
    9) if Q ≠ 0 then (5) else (10)
    10) if N = S then (11) else (12)
    11) Display N is a armstrong number goto (13)
    12) Display N is not a armstrong number
    13) STOP

Leave a Reply to admin Cancel Reply

Your email address will not be published. Required fields are marked *