0% found this document useful (0 votes)
20 views9 pages

Week 1-Familiarization With Programming Environment

C is a general-purpose programming language developed by Dennis M. Ritchie for UNIX, known for its efficiency, portability, and structured approach. It includes various sections such as documentation, linking, and function definitions, and supports problem-solving techniques like algorithms and flowcharts. C's character set consists of letters, digits, special characters, and whitespace, and it has predefined keywords and user-defined identifiers for variable naming.

Uploaded by

9d.tanvishpatil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Week 1-Familiarization With Programming Environment

C is a general-purpose programming language developed by Dennis M. Ritchie for UNIX, known for its efficiency, portability, and structured approach. It includes various sections such as documentation, linking, and function definitions, and supports problem-solving techniques like algorithms and flowcharts. C's character set consists of letters, digits, special characters, and whitespace, and it has predefined keywords and user-defined identifiers for variable naming.

Uploaded by

9d.tanvishpatil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Introduction to C

C is a general-purpose, high-level language that was originally developed by Dennis M.


Ritchie to develop the UNIX operating system at Bell Labs. The UNIX operating system, the
C compiler, and essentially all UNIX applications programs have been written in C. The C
has now become a widely used professional language for various reasons.

● Easy to learn
● Structured language
● It produces efficient programs
● It can handle low-level activities
● It can be compiled on a variety of computer platforms

Facts about C
C was invented to write an operating system called UNIX. C is a successor of B language
which was introduced around 1970. The language was formalized in 1988 by the American
National Standard Institute (ANSI). The UNIX OS was totally written in C by 1973. Today C
is the most widely used and popular System Programming Language. Most of the state-of-
the-art software have been implemented using C. Today's most popular Linux OS and
RBDMS MySQL have been written in C.

Why to use C?
C was initially used for system development work, in particular the programs that makeup the
operating system. C was adopted as a system development language because it produces code
that runs nearly as fast as code written in assembly language. Some examples of the use of C
might be:
● Operating Systems
● Language Compilers
● Assemblers
● Text Editors
● Print Spoolers
● Network Drivers
● Modern Programs
● Databases
● Language Interpreters
● Utilities

The largest measure of C's success seems to be based on purely practical considerations:
1. The portability of the compiler
2. The standard library concept
3. A powerful and varied repertoire of operators
4. An elegant syntax
5. Ready access to the hardware when needed
6. And the ease with which applications can be optimized by hand-coding isolated
procedures.

1
Problem Solving Techniques: The process of working through details of a problem to reach a
solution. There are three approaches to problem solving:
1. Algorithm
2. Flowchart
Structure of a C program
Documentation Section
Link Section /Include header file section
Definition Section
Global declaration section
Main() function section
{
Declaration part
Executable part
}
Subprogram section
Function 1
Function 2

Function n
(User defined functions)

Documentation Section:-
Documentation section consists of a set of comment lines giving the name of the program, the
author and other details.

Link section:-
Link section provides instructions to the compiler to link functions from the system library.

Definition Section:-
Definition section defines all symbolic constants.

Global Declaration:-
This section declares some variables that are used in more than one function. This section
also declares all the user defined functions.

Main() function section:-


Every C program must contain a main() function. This section contains two parts, declaration
and executable parts. Declaration part declares all the variables used in the executable part.
There is at least one statement in the executable part. Executable part contains the statements
following the declaration of the variables.

Subprogram section:-
This section contains all the user defined functions that are called in the main() function.

All sections, except the main () function and link section may be absent when they are not
required.

2
Character set of C language
The character set in C Language can be grouped into the following categories.
1.Letters
2.Digits
3.Special characters
4.White Spaces

White Spaces are ignored by the compiler until they are a part of string constant. White Space
may be used to separate words, but are strictly prohibited while using between characters of
keywords or identifiers.

C Character set table


The characters in C are grouped in to 4
1. Letters(A-Z, a-z)
2. Digits (0-9)
3. Special Characters
4. White spaces(used to separate words)

Special Characters

Escape sequences
1. BlankSpace(\b)
2. HorizontalTab(\t)
3. CarriageReturn(\r)
4. NewLine(\n)
5. Form Feed (\f)
6. Vertical Tab (\v)

3
Keywords and Identifiers

Every word in C language is a keyword or an identifier. Keywords are reserved words that
have standard, predefined meanings in C. All keywords must be written in lowercase.
Keywords in C language cannot be used as a variable name. They are specifically used by
the compiler for its own purpose and they serve as building blocks of a c program.
The following are the 32 Keywords of C language.

Identifier refers to the name of user-defined variables, array and functions. A variable should
be essentially a sequence of letters and or digits and the variable name should begin with a
character.
Both uppercase and lowercase letters are permitted. The underscore character is also
permitted in identifiers. The underscore (_) symbol can be used as an identifier.
Some examples of identifiers are: tax_rate, _temp, place etc.

Data Types
Data types are used to store various types of data that is processed by program. The definition
of a variable will assign storage for the variable and define the type of data that will be held
in the location.
C has different data types for different types of data and can be broadly classified as:

1. Primary data types

2. Secondary data types

4
Week 1: Familiarization with programming environment

The students are expected to


 Algorithm and flowchart
o Write an algorithm to draw a flowchart for swapping two numbers
o Write an algorithm and flowchart for finding the salary of an employee with
the following details:
 Basic salary is input through the keyboard.
 Dearness Allowance is 40% of the basic salary.
 House rent allowance is 20% of the basic salary.
o Write an algorithm to draw a flowchart to find the sum of 10 integers
 Understanding of the C program structure and the flow of execution
Solution:

 Algorithm: The algorithm is a step-by-step procedure to be followed in solving a


problem. It provides a scheme to solve a particular problem in finite number of
unambiguous steps. It helps in implementing the solution of a problem using any of the
programming languages.

 Flowchart: A flowchart is a graphical or symbolic representation of an algorithm. They


are basically used to design and develop complex programs to help the users to visualize
the logic of the program so that they can gain a better understanding of the program and
find flaws, bottlenecks, and other less obvious features within it. Basically, a flowchart
depicts the “flow” of a program. The following table shows the symbols used in flowchart
along with its descriptions.

5
1. Write an algorithm to draw a flowchart for swapping two numbers

Solution:
Algorithm
Step 1: Start
Step 2: Read the value of A
Step 3: Read the value of B
Step 4: Declare a temporary variable TEMP
Step 5: TEMP = A
Step 6: A = B
Step 7: B = TEMP
Step 8: Print A and B
Step 9: Stop

Flow diagram

6
2. Write an algorithm and flowchart for finding the salary of an employee with the
following details:
 Basic salary is input through the keyboard.
 Dearness Allowance is 40% of the basic salary.
 House rent allowance is 20% of the basic salary.

Solution:
Algorithm
Step 1: Start
Step 2: Input Basic_Salary
Step 3: Calculate DA = 0.40 × Basic_Salary
Step 4: Calculate HRA = 0.20 × Basic_Salary
Step 5: Calculate Gross_Salary = Basic_Salary + DA + HRA
Step 6: Display Gross_Salary
Step 7: Stop

Flow diagram

7
3. Understanding of the C program structure and the flow of execution

Solution:

The first program while learning any programming language is ‘Hello world’ program.
This program is used to check the programming environment. It will give you idea of
program editor, how to compile program and how to run program?
These programs are very useful in learning the menus, shortcut and increase our
confidence. It is the easiest program but still we have to run this program for
understanding programming. For every program you have to first :
Write a program code  compile (Ctrl+F9) Run (Alt +F9)  observe the output  save
your program (F2), you can also save your program before compiling.

1. Write a program to print “Hello world!” on screen (Hello.c)


Step 1: Type the program in C or C++ editor

Step 2: Click on compile to translate it into binary format (automatically .obj (object) file
created. Short cut for compiling is Ctrl +F9

8
Step 3: Run the program and automatically *.exe is generated. Short cut for run is
Alt +F9. Output window will show you the output.

You might also like