Docsity

C Programming: Understanding the Basics of C Language, Study notes of C programming

Partial preview of the text

Download C Programming: Understanding the Basics of C Language and more Study notes C programming in PDF only on Docsity!

UNIT- 1

1. PROGRAMMING PROCESS

2. OVERVIEW OF C

3. DATA INPUT/OUTPUT

THE PROGRAMMING PROCESS

 All programming involves creating something that solves a problem. The problems can range from

something of great scientific or national importance.

 This section describes one approach to solve such problems - think of it as a rough guide to the

things you should do when entering the land of programming.

 In broad terms, those things are:

 Identify the Problem

 Design a Solution

 Write the Program

 Check the Solution

 Of these, only the third step is usually called "programming“.

PROBLEM ANALYSIS

 The problem analysis helps in designing and coding for that particular problem.

 1. Input specifications The number of inputs and what forms the input are available

 2.Output specifications The number of outputs and what forms the output should be displayed.

 E-x input – a,b,c output - c

DESIGNING A PROGRAM

 Algorithms  Flowcharts  Algorithm - step by step procedure of solving a problem  Flowcharts – It is the graphical representation of the algorithm.  Coding- Writing instructions in a particular language to solve a problem.  Testing- After writing a program, programmer needs to test the program for completeness, correctness, reliability and maintainability.  Maintaining the program- It means periodic review of the programs and modifications based on user requirements.

EXAMPLE- 1

 Problem definition : To find simple interest  Problem Analysis :  inputs– p, r, t  Output– simple interest  Algorithm Step 1:Start  Step 2:input p,r,t  Step 3: calculate si=prt/  Step 4: output si  Step 5:stop

FLOWCHART

Example 1: Calculate the Interest of a Bank Deposit Algorithm:

  • Step 1: Read amount,
  • Step 2: Read years,
  • Step 3: Read rate,
  • Step 4: Calculate the interest with formula "Interest=AmountYearsRate/
  • Step 5: Print interest, Flowchart:

Example 2: Convert Temperature from Fahrenheit ( ℉ ) to Celsius ( ℃ ) Algorithm: Step 1: Read temperature in Fahrenheit, Step 2: Calculate temperature with formula C=5/9*(F-32), Step 3: Print C, Flowchart:

Example 4: Determine Whether A Student Passed the Exam or Not: Algorithm:

  • Step 1: Input grades of 4 courses M1, M2, M3 and M4,
  • Step 2: Calculate the average grade with formula "Grade=(M1+M2+M3+M4)/4"
  • Step 3: If the average grade is less than 60, print "FAIL", else print "PASS".

PROGRAM

 Programming is then the task of describing your design to the computer: teaching it your way of solving the problem.  There are usually three stages to writing a program:  Coding  Compiling  Debugging

COMPILATION

Compilation is actually the process of turning the program written in some programming language into the instructions made up of 0 's and 1 's that the computer can actually follow. This is necessary because the chip that makes your computer work only understands binary machine code - something that most humans would have a great deal of trouble using since it looks something like: 01110110 01101101 10101111 00110000 00010101 Early programmers actually used to write their programs in that sort of a style - but luckily they soon learnt how to create programs that could take something written in a more understandable language and translate it into this gobbledy gook. These programs are called compilers and you can think of them simply as translators that can read a programming language, translate it and write out the corresponding machine code. Compilers are notoriously pedantic though - if you don't write very correct programs, they will complain. Think of them as the strictest sort of English teacher, who picks you up on every single missing comma, misplaced apostrophe and grammatical error.

DEBUGGING

This is where debugging makes it first appearance, since once the compiler has looked at your program it is likely to come back to you with a list of mistakes as long as your arm. Don't worry though, as this is perfectly normal - even the most experienced programmers make blunders. Debugging is simply the task of looking at the original program, identifying the mistakes, correcting the code and recompiling it. This cycle of code - > compile - > debug will often be repeated many many times before the compiler is happy with it. Luckily, the compiler never ever gets cross during this process - the programmer on the other hand... It should also be said at this point that it isn't actually necessary to write the entire program before you start to compile and debug it. In most cases it is better to write a small section of the code first, get that to work, and then move on to the next stage. This reduces the amount of code that needs to be debugged each time and generally creates a good feeling of "getting there" as each section is completed. Finally though, the compiler will present you with a program that the computer can run: hopefully, your solution!

In the year 1988 'C' programming language standardized by ANSI (American national

standard institute), that version is called ANSI-C. In the year of 2000 'C' programming

Language standardized by 'ISO' that version is called C- 99

Where we use C Language

C Language is mainly used for;

  • Design Operating system
  • Design Language Compiler
  • Design Database
  • Language Interpreters
  • Utilities
  • Network Drivers
  • Assemblers

NEED OF PROGRAMMING

 Programming language is important because it defines the relationship, semantics and grammar which allows the programmers to effectively communicate with the machines that they program.  A programming language serves several purposes:  You can instruct the computer what to do in a human-readable form  Allows the programmer to structure the instructions into functions, procedures , etc.  This also allows the program to be broken into "chunks" which can be developed by a group of developers  Provides portability - the low-level instructions of one computer will be different from that of another computer.  Computer programmers have a full understanding of the how and why of computer systems, including system limitations, and can set realistic expectations and work around those limitations to fully maximize the use of the equipment and its accessories.  Computer programming principles implemented today will likely influence how technologies such as voice- recognition, artificial intelligence and other sophisticated technologies will change in the future and how they will be applied to our day-to-day lives.  Programming is important for speeding up the input and output processes in a machine. Programming is important to automate, collect, manage, calculate, analyze the processing of data and information accurately.