2. INTRODUCTION TO C
• It is a structured programming language used to develop operating
system, business system, word processing, database system e.t.c
• Developed by Dennis Ritchie at the Bell Laboratories in 1972 to develop
the UNIX operating system.
• At the time, Bell Labs had a programming language named B — B for
Bell. The next language they created was C — one up on B.
• C is the offspring of both the B programming language and a
language named BCPL, which stood for Basic Combined Programming
Language.
• It is modular language. C code can be written in routines called
functions. These functions can be reused in other applications or
programs.
• It is case sensitive language.
4. 1. #include is known as a preprocessor directive. It tells
the compiler to “include” text from another file,
stuffing it right into source code. Doing this avoids lots
of little, annoying errors.
2. <stdio.h> is a filename surrounded by angle brackets.
The whole statement #include <stdio.h> tells the
compiler to take text from the file STDIO.H and stick it
into source code before the source code is compiled.
The STDIO.H file itself contains information about the
Standard Input/output functions required by most C
programs. The H means “header.”
5. 3. The int identifies the function main as an integer
function, meaning that main() must return an
integer value when it’s done. The function main,
which also identifies the first and primary function
inside the program.
4. Two empty parentheses follow the function name.
5. All functions in C have their contents encased by
curly braces.
6. printf() job is to display information(output) on the
screen. The added f means “formatted,”.
6. 7. printf() has a set of parentheses, which consists of text, or a
“string” of characters. Everything between the double quote
characters (“) is part of printf’s text string.
8. ‘n’ called a newline in C are called wildcard characters.
9. The printf line, or statement, ends with a semicolon. The
semicolon tells the C compiler where one statement ends and
another begins. Note that all statements require semicolons in
C, even if only one statement is in a program or function.
10. The return command sends the value 0 (zero) back to the
operating system when the main() function is done. Returning a
value is required as part of the main() function. This statement
ends in a semicolon.
7. QUIZ!
1. The core function in every C language program is called
A. numero_uno().
B. main().
C. primus().
D. core().
2. Functions require parentheses because
A. They talk in whispers.
B. The parentheses keep the function warm.
C. The parentheses hold various things required by or belonging to
the function.
D. None
9. VARIABLES
• A variable is a named data storage location on computers memory. By
using variable name on our program we are, in effect referring to the
data stored there.
• For many compilers, a variable name can be up to 31 character long. But
it can be actually longer than that)
• Rules for naming a variable:-
• The name can contain letters, digit and the underscore character(_).
• The first character of the name must be a letter. The underscore is also
legal but it’s not recommended.
• Case matters.
• C keywords cannot be used as a variable name.
• It should not contain any other special character than underscore(_).
• A variable name mustn’t have any embedded space.
10. • Declaring a variable:-
• A variable declaration tells the compiler the name and the type of a variable and
optionally initializes the variable to a specific value.
• A variable declaration has following form:-
Data_type_name variable name;
Eg: int roll,num;
float percentage;
• Data Type:
• The data type defines the values that needs to be stored in a program.
• C supports mainly two type of data types:
1. Primary data types
2. Derived data types
3. User defined data type
11. PRIMARY DATA TYPE
Data type Data sub_type Bytes Format Range
Character
Signed 1 %c -128 to 127
Unsigned 1 %c 0 to 255
Numeric
Sort Signed int 2 %d -32768 to 32767
Sort Unsigned int 2 %d 0 to 65535
Long Signed int 4 %1d -2147483648 to
2147483647
Long Unsigned int 4 %1d 0 to 4294967295
Float 4 %f 3.4E-38 to 3.4E+38
Double 8 %1f 3.7E-308 to
3.4E+308
Long double 10 %1f 3.4E-4932 to
3.4E + 4932
12. • Derived Data Types:
• Functions, arrays and pointers are derived data type.
• User Defined Data Type:
• The user defined datatype identifier can later be used to
declare variables.
• The user defined data types are:
• Structure
• Union
• Enumeration
13. CONSTANT
• A constant is the fixed value that do not change during the execution
of the program.
• C supports four constants:-
• Character
• String
• Integer
• floating-point constants.
• The numeric constants(integer and floating-point) must adhere
following rules:-
1. Commas and blank spaces cannot be included within the
constants.
2. The constant can be preceded by a minus(-) sign if desired.
3. The value of constant cannot exceed specified minimum and
maximum bounds
14. QUIZ
1. Which of the following variable name is not a valid variable name?
a) Annual_profit
b) _2009_tax
c) Saving#account
d) Year2x5_abc
2. How many bytes of memory does a double data type take ?
a) -32768 to 32767
b) 0 to 255
c) 4
d) 8
15. 1. Which of the valid format specifier for string type value?
a) %d
b) %c
c) %st
d) %s
2. What is the range of short signed Integer?
a) -32768 to 32767
b) 0 to 255
c) 0 to 65535
d) 3.7E-308 to 3.4E+308
17. OPERATOR
• Operator is a symbol which helps the user to command the computer
to do certain mathematical or logical manipulation.
• Types of operator
• Arithmetic Operator
• Assignment Operator
• Unary Operator
• Relational Operator
• Logical Operator
• Ternary operator
• Comma Operator
• Bitwise Operator
• Size of Operator
18. 1) Arithmetic Operator
Basic mathematical operation.
Operator Symbol
Addition +
Subtraction -
Multiplication *
Division /
Modulus %
(Returns Reminder)
2) Assignment Operator
Is used to assign Values.
Some of them are =,+=,-=,*=,/=,%=
19. 3. Unary Operator:
• It is so called because they take a single operand. It acts upon
single operand to be increased or decreased by one.
• Operator Symbol action Example
Increment ++ Increments the operand by one x++,++x
Decrement -- Decrements the operand by one x--,--x
• They differ in which mode they are used.
• When used in prefix mode, the increment and decrement
operators modify their operand before it’s used.
• When Used in postfix mode, the increment and decrement
operators modify their operand after it’s use.
20. 4. Relational Operator:-
It is used to compare expressions. An expression containing a relational
operator evaluates to either true or false.
Operator Symbol
Equal ==
Greater than >
Less than <
Grater than or equal to >=
Less than or equal to <=
Not Equal !=
21. 5. Logical Operator:-
It let’s us to combine two or more relational expression into a single expression
that evaluates to either true or false.
Operator Symbol
AND &&
OR ||
NOT !
6. Ternary Operator:-
It is used to check certain relational expression and execute the true statement if
the condition is true and display if the condition is false.
Syntax:
[condition] ? [true statement]:[false statement]
Example:
a>b ? printf (“a is greater”) : printf (“b is greater”);
22. 7. Bitwise Operator:-
These operators are used for having bit level computations of different values.
Operator Meaning
& bitwise AND
| bitwise OR
^ bitwise exclusive OR
>> shift cells right
>> shift cells left
- one’s complement
6. Size of () Operator:-
Returns the number of bytes occupied in the memory
Syntax:
sizeof(datatype/variable);
Example:
sizeof(int);
23. ESCAPE SEQUENCE
• These are characters not printed when used but provide various
functions. These are always started with a backslash ‘’. Commonly
Used are:-
• Constant Meaning
‘a’ Audible Alert
‘b’ backspace
‘f’ Form feed
‘n’ New Line
‘r’ Carriage Return
‘t’ Horizontal Tab
‘V’ Vertical Tab
‘’’ Single quote
‘”’ Double quote
‘?’ Question mark
‘’ Back slash
‘0’ Null
24. HEADER FILES
• Header File contains definition of functions and variables which
can be incorporated into any c program by using the preprocessor
#include statement. All header files have the extension .h.
• Some commonly used Header files:
• Stdio.h : It contains the standard input and output functions like
printf(), scanf(),gets(),puts() etc.
• Conio.h : It contains some of the functions like getch(), clrscr()
etc.
• Math.h : It contains the mathematical functions like strlen(),
strcpy(), strcmp(), strrev() etc.
• Ctype.h : it contains some validating functions like isdigit(),
isalnum(), isalpha() and some converting functions like
toupper(), tolower() etc.
26. • WAP to calculate the area and circumference of a circle . Where radius of a
circle is input by user and define pi as constant.
• WAP to read principle, time and rate to calculate the simple interest and total
amount .
• WAP to convert temperature in Fahrenheit into centigrade and vice versa.
• WAP to ask cost of pen in Paisa. Convert it into nearest rupees and paisa.
• WAP to enter distance between two cities in KM and convert it into meter,
centimeter, inch and feet.
• WAP to enter any 4 digit number and find the sum of the first and last digit of the
number.[e.g. Any four digit number =4567, sum =4+7].
• WAP to supply length and breadth of a rectangle. Find out area and perimeter.
27. • WAP to find total and percentage of the students whose marks are as follows:
• WAP to enter 4 digit number and find the sum of them.[e.g.
1234=1+2+3+4=10].
• WAP to interchange the contents of x and y after entering the value of x and
y
• WAP to read the radius of the sphere and find the volume and area of it.
Subjects Marks
English 65
Nepali 75
Computer Science 70
Math 80
Account 60
28. • WAP to find the area of triangle after reading the value of base and
height.
• WAP to find the compound interest. The value principle, time and
interest rate is given by user.
• WAP to find the area of a triangle, if the length of the side of a triangle
are denoted by a, b, c then area of triangle id given by
Area= 𝒔 𝒔 − 𝒂 𝒔 − 𝒃 𝒔 − 𝒄 𝐰𝐡𝐞𝐫𝐞 𝒔 =
(𝒂+𝒃+𝒄)
𝟐
.
• Basic salary of Sabin is input through keyboard. His medical
allowance is 10% of the basic salary and provident fund is 10% of the
basic salary. WAP to find his net salary.
• WAP to solve the quadratic equation a𝒙 𝟐
+ b𝒙 + 𝒄 = 𝟎 , 𝒘𝒉𝒆𝒓𝒆
x=
−𝒃±𝒃 𝟐−𝟒𝒂𝒄
𝟐𝒂