SlideShare a Scribd company logo
1 of 10
Download to read offline
Introduction to C Programming                      Class : 8

The C programming language is a popular and widely used programming language for
creating computer programs. Dennis Ritchie at AT & T Bell Laboratories developed the
C language three decades ago. It is an efficient, flexible and portable language.
Portability refers to the case in which a unit of software written on one computer may be
moved to another computer without any or little modification.
C has a wide diversity of operators and commands. C can be effectively utilized for
development of system software like, operating systems, compilers, text processors,
and database management systems. C is well suited for developing application
programs too.

The C language is composed of the following basic types of elements: keywords,
Constants, Identifiers, operators & punctuation. These elements are collectively
known as tokens. A token is a source program text that the compiler does not break
down into component elements.

Character Set
The characters used in C language are grouped into three classes.
    Alphabetic characters (a, b, c, …., z) (A, B, C, ….., Z)
    Numeric characters 0 through 9
    Special characters
Constants
A constant is of numeric or non-numeric type. It can be a number, a character or a
character string that can be used as a value in a program. As the name implies, the
value of a constant cannot be modified. Numeric data is primarily made up of numbers
and can include decimal points. Non-numeric data may be composed of numbers,
letters, blanks and any special characters supported by the system.
Numeric constants are of three types:
     integer constant
     floating-point constant
     character constant
Integer Constant
An integer constant is a decimal number (base 10) that represents an integral value (the
whole number). It comprises of the digits 0 to 9. Integer constants are positive unless
they are preceded by a minus sign and hence –18 is also a valid integer constant.
Special characters are not allowed in an integer constant. The constant 2,345 is an
invalid integer constant because it contains the special character.

Floating - point Constant
A floating-point constant is a signed real number. It includes integer portion, a decimal
point, fractional portion and an exponent. While representing a floating point constant,
either the digits before the decimal point (the integer portion) or the digits after the
decimal point (the fractional portion) can be omitted but not both. The decimal point can
be omitted if an exponent is included. An exponent is represented in powers of 10 in
decimal system.
                       Example: 58.64 is a valid floating-point (real) constant.
Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil                 1
Character Constant
A character is a letter, numeral or special symbol, which can be handled by the
computer system. These available symbols define the system’s character set. Enclosing
a single character from the system’s character set within single quotation marks form a
character constant.
Example: ‘1’, ‘a’, ‘+’, and ‘-‘ are the valid character constants.

Escape Sequences
Character combinations consisting of a backslash  followed by a letter is called escape
sequence. An escape sequence may be used to represent a single quote as a character
constant. Similarly some nonprintable characters are represented using escape
sequence characters.

Examples:
‘a’ Bell (beep)
‘b’ Backspace
‘f’ Form feed
‘r’ Carriage return
‘n’ New line
‘0’ null character

String Literal
A string literal or a string constant is a sequence of characters from the system’s
character set, enclosed in double quotes. By default, the null character ‘0’ is assumed
as the last character in a string literal. “hello” is a valid string literal. The actual number
of characters in this string literal is 6 including the null character at the last. The null
character is invisible here. Six bytes are required to store this string in memory.
However, the physical length of this string is 5 characters.

Identifiers
Identifiers are the names that are to be given to the variables, functions, data types and
labels in a program.

The valid variable names are:
X     length         x_value                         y_value              a123

Rules to name a variable:
     The name of a variable can consist of alphabets (letters) and numbers.
     Other characters are not allowed in the name of a variable.
     An underscore character can be used as a valid character in the variable name.
     The variable name starts with an alphabet and its length may vary from one
      character to 32 characters.
     The first character in a variable’s name should be an alphabet, ie., a number is not
      allowed as a first character in the variable name.
     Keywords (which have special meaning in C) cannot be used as identifiers.



Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil                      2
Fundamental Data Types
Data is one of the most commonly used terms in programming. Data can be defined as
the raw information input to the computer. Data is differentiated into various types in C.
There are three numeric data types that comprise the fundamental or primary data
types. The fundamental data types are: int, float and char. They are also called as pre-
defined primitive types associated with the C compiler. The C compiler knows about
these types and the operations that can be performed on the values of these types. The
following are the declaration statements of variables of different types:

int x;
float f;
char ch;
We know already that an integer is a whole number, a float is a real number and a
character is represented within single quotes.

Example:
1 is an integer (whole number)
1.0 is a real number (floating point number)
‘1’ is a character constant
“1” is a string literal

An integer requires 2 bytes of memory to store its value, a float requires 4 bytes of
memory and a character requires 1 byte of memory.

Operators
C has rich set of operators. An operator is defined as a symbol that specifies an
operation to be performed. Operators inform the computer what tasks it has to perform
as well as the order in which to perform them. The order in which operations are
performed is called the order of precedence. It is also called hierarchy. The direction
in which operations are carried out is called associativity.

There are three types of operators in C.

     Unary operators
     Binary operators
     Ternary operator

Unary Operators
Order of precedence is high for the unary operators and they have only one operand.
The order of evaluation (associativity) is from right to left.

The increment (++) or decrement (--) operator is used to increase or to decrease the
current value of a variable by 1. Generally the unary operators appear before the
operand.

There are two forms:
Postfix increment or decrement
Prefix increment or decrement
Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil                 3
The unary operators ++ and -- are called prefix increment or decrement operators when
they appear before the operand. The unary operators ++ and -- are called postfix
increment or decrement operators when they appear after the operand.

Binary Operators

Arithmetic Operators
The arithmetic operators +, -, *, /, and % are binary operators as they have two
operands. All the arithmetic operators observe left to right associativity.




The arithmetic operators can be used with integers and float values. The modulus
operator works with integers only and it gives the remainder value after division.

Relational Operators
The relational or Boolean operators are binary operators as they always have two
operands. All the relational operators observe left to right associativity, that is, they are
evaluated from left to right.




Logical Operators

The logical operators “&&” and “||” are used to connect two or more relational
expressions. The “&&” operator is the logical AND operator and it returns a value of true
if both of its operands evaluate to true. A value of false is returned if one or both of its
operands evaluate to false.
The logical OR operator “||” returns a value of true when one or both of its operands
evaluates to true and a value of false when both of its operands evaluate to false.
Assignment Operators
The assignment operator (=) assigns the value of the right-hand operand to the
left-hand operand. C has arithmetic-assignment operators too.
They are +=, - =, *=, /= and %=.

Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil                    4
Consider the following statement:
             i = i + 1;
Here, the old value of the variable i is incremented by 1 and the incremented value is
stored as the new value of i. The above statement can be represented in the following
ways.
       Using the arithematic - assignment operator,
              i += 1;
In the above statement, the operator += is used to increment the old value of i by one
and the new value is stored in the variable I itself. Similarly, the statement i *= 2;
represents that the old value of i is multiplied by 2 and the new value is stored in i itself.

The order of evaluation
Using the precedence of operators, we will see how to evaluate an expression. The
bracketed expression should be evaluated first.

        Consider the following expression
              5 * 2 + 8 + (3 – 2) * 5
        It will be evaluated as follows:
        5*2+8+1*5             (bracketed expression is evaluated first)
        10 + 8 + 5            (multiplication has higher precedence over addition)
        23                    (the value of the expression is 23)

Ternary Operator
C has one ternary operator, which is a conditional operator. The symbol used for this
operator is ?: and it has three operands.

The syntax of the conditional operator is as follows:
conditional expression? expression 1 : expression 2;
If the conditional expression is true, expression 1 is evaluated.
If the conditional expression is false, expression 2 is evaluated.

Example :
The following example show the uses of conditional operator:
         c = (a > b) ? a : b;
If a is greater than b, the value of a is assigned to c else the value of b is assigned to c.
Punctuations
C’s punctuation symbols and their uses are listed as follows:

[]      - used to represent array index (square brackets)
{}      - used to cover the body of the function (curly braces)
()      - used to represent a function, to group items and to group expressions
          (simple parentheses)
<>      - used to enclose a header file in a preprocessor statement (angular brackets)
““      - used to represent string literals (double quotes)
‘‘      - used to represent a character constant (single quotes)
Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil                         5
/* */ - used to represent a comment
;     - used as a statement terminator
,     - used to separate items
blank and white space – used to improve readability of the program.

Structure of C Program
A program is defined as a set of instructions to be executed sequentially to obtain the
desired result. A function is a program, which is being used to carry out some small
task. C programs can be very small. C programs are made up of functions. A program
cannot be written without a function. A function may be pre-defined or user-defined.

# include <stdio.h>
main()
{
  printf(“Welcome to C Programming”);
}

This program, upon execution, will display the message Welcome to C Programming
on the screen. The user has to define the main() function to provide necessary code.
When a C program runs, the control is transferred to this function. This is called the
program’s entry point. The program has two functions, one is the user-defined main()
function which is the entry point and the other one is printf() function which is
pre-defined and used to display the results on the standard output (screen or monitor).
Simple parentheses () are used to represent a function. Here main() is the calling
function and printf() is the called function.

The first line in the program # include <stdio.h> is a preprocessor statement. #include
is a preprocessor directive. The preprocessor is a software program that will expand the
source code while the program is compiled. The #include <stdio.h> statement includes
the contents of the stdio.h file (standard input and output header file) globally, that is,
prior to the main() function. The contents of the stdio.h file are the function declaration
statements of the pre-defined output and input functions like printf() and scanf() etc.

Statements
Each and every line of a C program can be considered as a statement. There are
generally four types of statements. They are:

       Preprocessor statement
       Function header statement
       Declaration statement
       Executable statement
As you know already, the preprocessor statement is used to expand the source code by
including the function declaration statements from the specified header files. The
function header statement is used as a first line in the definition of a function. The
declaration statements are further classified into variable declaration statements and
function declaration statements.


Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil                  6
Input and Output Statements
The function printf() is used to display the results on the standard output (screen). We
have seen the use of printf() to display the string on the monitor. Actually, the first
parameter of the printf() function is a string which is used to control the output and,
hence it can be called as “control string”. This parameter is used to format the output
for display and hence we can also call it as a “formatting string”.

Example:
To print a value of an integer:
int n; /* variable n is declared as integer*/
n = 10;
printf(“%d”, n);

In the above example, ‘%d’ is used as a formatting character within the control string of
printf() function to display the value of an integer. The control string of printf() function
can take three types of characters.
     Ordinary characters
     Formatting characters
     Escape sequence characters

Ordinary characters within the control string are displayed as such. In the case of
printf(“hello”); statement, the control string has ordinary characters only. They are
displayed as such on the screen. The following table lists the formatting characters used
to display the values of various types.




Input from keyboard
To read a value from the keyboard (standard input), the function scanf() is used. The
code segment to read a value for an integer variable x is given below:

int x;
scanf(“%d”, &x);

While the scanf() function is being executed, the system waits for the user’s input. The
user has to provide data through keyboard. The data will be placed in the location of x
only after “Enter” key is pressed in the keyboard. The second parameter of the above
scanf() function is &x, which represents the address of x. & is the address of operator
and when it is being used with a variable, it provides the address of that variable.

Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil                         7
Lab Exercises

1.      Write a C program to display a message “Welcome to C programming”.

        # include <stdio.h>
        # include <conio.h>
        main()
        {
          clrscr();
          printf(“Welcome to C programming”);
          getch();
        }

2.      Write a C program to find the sum of 2 numbers.

        # include <stdio.h>
        # include <conio.h>
        main()
        {
          int a,b,c;
          printf(“nEnter any 2 numbers:”);
          scanf(“%d %d”,&a,&b);
          c=a+b;
          printf(“nSum of 2 nos=%d”,c);
          getch();
        }


3.      Write a C program to find the area of rectangle.

        # include <stdio.h>
        # include <conio.h>
        main()
        {
           float a,l,b;
           printf(“nEnter Length & Breadth:”);
          scanf(“%f %f”,&l,&b);
          a=l*b;
          printf(“nArea of Rectangle=%f”,a);
          getch();
        }

Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil      8
4.      Write a C program to calculate simple interest.

        # include <stdio.h>
        # include <conio.h>
        main()
        {
           float p,n,r,si;
           printf(“nEnter values of P,N & R:”);
          scanf(“%f %f %f”,&p,&n,&r);
          si=(p*n*r)/100;
          printf(“nSimple Interest=%f”,si);
          getch();
        }


5.      Write a C program to find the area of triangle.

        # include <stdio.h>
        # include <conio.h>
        main()
        {
           float a,b,h;
           printf(“nEnter Base & Height:”);
          scanf(“%f %f”,&b,&h);
          a=0.5*b*h;
          printf(“nArea of Triangle=%f”,a);
          getch();
        }



                                             Question Bank

2 mark questions:
1.    Write a short note on C Programming.
2.    What are tokens ? Name them.
3.    Write a note on Character Set.
4.    Define constants.
5.    What are the types of constants ?
6.    What do you mean by integer constants ?
7.    Write a note on floating point constants.
8.    What are character constants ?



Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil   9
9.    Define escape sequence.
10.   Write a note on String literal.
11.   Define identifiers.
12.   Define operator in C.
13.   What is hierarchy ?
14.   Define associativity.
15.   What are the types of operators ?
16.   Write a note on Unary operators.
17.   Write a note on Arithmetic operators in C.
18.   What are the relational operators in C.
19.   Write a note on logical operators.
20.   What is the purpose of Assignment operator in C.
21.   What are the types of statements used in C.
22.   Write a C program to display a message “Welcome to C programming”.
23.   List down the formatting characters used to display the values of various types.

5 mark questions:
1.    What are the features of C language ?
2.    Write a note on escape sequences in C language.
3.    List down the rules to name a variable in C.
4.    Explain the fundamental data types in C programming.
5.    Explain the order of evaluation in C with an example.
6.    Explain conditional operator with an example.
7.    Explain printf statement in C language.
8.    How do you input data from keyboard ?
9.    Write a C program to find the sum of 2 numbers.
10.   Write a C program to find the area of rectangle.
11.   Write a C program to calculate simple interest.
12.   Write a C program to find the area of triangle.

8 mark questions:

1.    Explain the types of constants in C language.
2.    Explain Binary operators in C.
3.    Explain the structure of C program.
4.    Explain the punctuation symbols used in C language.



                                           *************************




Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil                  10

More Related Content

What's hot

Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programmingRumman Ansari
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programmingKamal Acharya
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programmingprogramming9
 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variablessangrampatil81
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constantsvinay arora
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programmingHarshita Yadav
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++Sachin Yadav
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
C presentation book
C presentation bookC presentation book
C presentation bookkrunal1210
 
Inline function
Inline functionInline function
Inline functionTech_MX
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Vishvesh Jasani
 

What's hot (20)

Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
C tokens
C tokensC tokens
C tokens
 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
 
Array in c
Array in cArray in c
Array in c
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constants
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
C functions
C functionsC functions
C functions
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
C presentation book
C presentation bookC presentation book
C presentation book
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Learn C
Learn CLearn C
Learn C
 
Inline function
Inline functionInline function
Inline function
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 

Viewers also liked

Viewers also liked (13)

+2 Computer Science - Volume II Notes
+2 Computer Science - Volume II Notes+2 Computer Science - Volume II Notes
+2 Computer Science - Volume II Notes
 
BASIC Programming Language
BASIC Programming LanguageBASIC Programming Language
BASIC Programming Language
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Programs of C++
Programs of C++Programs of C++
Programs of C++
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
class c++
class c++class c++
class c++
 
Scientific calculator in c
Scientific calculator in cScientific calculator in c
Scientific calculator in c
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
 
Computer Hardware Servicing Learner's Material Grade 10
Computer Hardware Servicing Learner's Material Grade 10Computer Hardware Servicing Learner's Material Grade 10
Computer Hardware Servicing Learner's Material Grade 10
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 

Similar to C programming | Class 8 | III Term

Fundamentals of C Programming Language
Fundamentals of C Programming LanguageFundamentals of C Programming Language
Fundamentals of C Programming LanguageRamaBoya2
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++Aahwini Esware gowda
 
Introduction to C Programming - R.D.Sivakumar
Introduction to C Programming -  R.D.SivakumarIntroduction to C Programming -  R.D.Sivakumar
Introduction to C Programming - R.D.SivakumarSivakumar R D .
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c languageAkshhayPatel
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic Manzoor ALam
 
data type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de ladata type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de laLEOFAKE
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2dplunkett
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptxAnisZahirahAzman
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++Rokonuzzaman Rony
 

Similar to C programming | Class 8 | III Term (20)

Fundamentals of C Programming Language
Fundamentals of C Programming LanguageFundamentals of C Programming Language
Fundamentals of C Programming Language
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
 
Introduction to C Programming - R.D.Sivakumar
Introduction to C Programming -  R.D.SivakumarIntroduction to C Programming -  R.D.Sivakumar
Introduction to C Programming - R.D.Sivakumar
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
C program
C programC program
C program
 
C Token’s
C Token’sC Token’s
C Token’s
 
C basics
C basicsC basics
C basics
 
C basics
C basicsC basics
C basics
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
Basics of c
Basics of cBasics of c
Basics of c
 
data type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de ladata type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de la
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
Python
PythonPython
Python
 
Ch02
Ch02Ch02
Ch02
 
C material
C materialC material
C material
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 

More from Andrew Raj

Term 3 class8_2019-2020
Term 3 class8_2019-2020Term 3 class8_2019-2020
Term 3 class8_2019-2020Andrew Raj
 
Class7 term3 2019-2020
Class7 term3 2019-2020Class7 term3 2019-2020
Class7 term3 2019-2020Andrew Raj
 
Class6 term2 2019-20
Class6 term2 2019-20Class6 term2 2019-20
Class6 term2 2019-20Andrew Raj
 
Term II - [2019-'20]_Class 7_CSC
Term II - [2019-'20]_Class 7_CSCTerm II - [2019-'20]_Class 7_CSC
Term II - [2019-'20]_Class 7_CSCAndrew Raj
 
Term II - [2019-'20]_Class 8_CSC
Term II - [2019-'20]_Class 8_CSCTerm II - [2019-'20]_Class 8_CSC
Term II - [2019-'20]_Class 8_CSCAndrew Raj
 
Computer Science Class - 8 Term - 1 2019_20
Computer Science Class - 8 Term - 1 2019_20Computer Science Class - 8 Term - 1 2019_20
Computer Science Class - 8 Term - 1 2019_20Andrew Raj
 
Computer Science - Class7 term-1 (2019_20)
Computer Science - Class7 term-1 (2019_20)Computer Science - Class7 term-1 (2019_20)
Computer Science - Class7 term-1 (2019_20)Andrew Raj
 
Class9 js word_quar2018
Class9 js word_quar2018Class9 js word_quar2018
Class9 js word_quar2018Andrew Raj
 

More from Andrew Raj (8)

Term 3 class8_2019-2020
Term 3 class8_2019-2020Term 3 class8_2019-2020
Term 3 class8_2019-2020
 
Class7 term3 2019-2020
Class7 term3 2019-2020Class7 term3 2019-2020
Class7 term3 2019-2020
 
Class6 term2 2019-20
Class6 term2 2019-20Class6 term2 2019-20
Class6 term2 2019-20
 
Term II - [2019-'20]_Class 7_CSC
Term II - [2019-'20]_Class 7_CSCTerm II - [2019-'20]_Class 7_CSC
Term II - [2019-'20]_Class 7_CSC
 
Term II - [2019-'20]_Class 8_CSC
Term II - [2019-'20]_Class 8_CSCTerm II - [2019-'20]_Class 8_CSC
Term II - [2019-'20]_Class 8_CSC
 
Computer Science Class - 8 Term - 1 2019_20
Computer Science Class - 8 Term - 1 2019_20Computer Science Class - 8 Term - 1 2019_20
Computer Science Class - 8 Term - 1 2019_20
 
Computer Science - Class7 term-1 (2019_20)
Computer Science - Class7 term-1 (2019_20)Computer Science - Class7 term-1 (2019_20)
Computer Science - Class7 term-1 (2019_20)
 
Class9 js word_quar2018
Class9 js word_quar2018Class9 js word_quar2018
Class9 js word_quar2018
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

C programming | Class 8 | III Term

  • 1. Introduction to C Programming Class : 8 The C programming language is a popular and widely used programming language for creating computer programs. Dennis Ritchie at AT & T Bell Laboratories developed the C language three decades ago. It is an efficient, flexible and portable language. Portability refers to the case in which a unit of software written on one computer may be moved to another computer without any or little modification. C has a wide diversity of operators and commands. C can be effectively utilized for development of system software like, operating systems, compilers, text processors, and database management systems. C is well suited for developing application programs too. The C language is composed of the following basic types of elements: keywords, Constants, Identifiers, operators & punctuation. These elements are collectively known as tokens. A token is a source program text that the compiler does not break down into component elements. Character Set The characters used in C language are grouped into three classes.  Alphabetic characters (a, b, c, …., z) (A, B, C, ….., Z)  Numeric characters 0 through 9  Special characters Constants A constant is of numeric or non-numeric type. It can be a number, a character or a character string that can be used as a value in a program. As the name implies, the value of a constant cannot be modified. Numeric data is primarily made up of numbers and can include decimal points. Non-numeric data may be composed of numbers, letters, blanks and any special characters supported by the system. Numeric constants are of three types:  integer constant  floating-point constant  character constant Integer Constant An integer constant is a decimal number (base 10) that represents an integral value (the whole number). It comprises of the digits 0 to 9. Integer constants are positive unless they are preceded by a minus sign and hence –18 is also a valid integer constant. Special characters are not allowed in an integer constant. The constant 2,345 is an invalid integer constant because it contains the special character. Floating - point Constant A floating-point constant is a signed real number. It includes integer portion, a decimal point, fractional portion and an exponent. While representing a floating point constant, either the digits before the decimal point (the integer portion) or the digits after the decimal point (the fractional portion) can be omitted but not both. The decimal point can be omitted if an exponent is included. An exponent is represented in powers of 10 in decimal system. Example: 58.64 is a valid floating-point (real) constant. Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 1
  • 2. Character Constant A character is a letter, numeral or special symbol, which can be handled by the computer system. These available symbols define the system’s character set. Enclosing a single character from the system’s character set within single quotation marks form a character constant. Example: ‘1’, ‘a’, ‘+’, and ‘-‘ are the valid character constants. Escape Sequences Character combinations consisting of a backslash followed by a letter is called escape sequence. An escape sequence may be used to represent a single quote as a character constant. Similarly some nonprintable characters are represented using escape sequence characters. Examples: ‘a’ Bell (beep) ‘b’ Backspace ‘f’ Form feed ‘r’ Carriage return ‘n’ New line ‘0’ null character String Literal A string literal or a string constant is a sequence of characters from the system’s character set, enclosed in double quotes. By default, the null character ‘0’ is assumed as the last character in a string literal. “hello” is a valid string literal. The actual number of characters in this string literal is 6 including the null character at the last. The null character is invisible here. Six bytes are required to store this string in memory. However, the physical length of this string is 5 characters. Identifiers Identifiers are the names that are to be given to the variables, functions, data types and labels in a program. The valid variable names are: X length x_value y_value a123 Rules to name a variable:  The name of a variable can consist of alphabets (letters) and numbers.  Other characters are not allowed in the name of a variable.  An underscore character can be used as a valid character in the variable name.  The variable name starts with an alphabet and its length may vary from one character to 32 characters.  The first character in a variable’s name should be an alphabet, ie., a number is not allowed as a first character in the variable name.  Keywords (which have special meaning in C) cannot be used as identifiers. Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 2
  • 3. Fundamental Data Types Data is one of the most commonly used terms in programming. Data can be defined as the raw information input to the computer. Data is differentiated into various types in C. There are three numeric data types that comprise the fundamental or primary data types. The fundamental data types are: int, float and char. They are also called as pre- defined primitive types associated with the C compiler. The C compiler knows about these types and the operations that can be performed on the values of these types. The following are the declaration statements of variables of different types: int x; float f; char ch; We know already that an integer is a whole number, a float is a real number and a character is represented within single quotes. Example: 1 is an integer (whole number) 1.0 is a real number (floating point number) ‘1’ is a character constant “1” is a string literal An integer requires 2 bytes of memory to store its value, a float requires 4 bytes of memory and a character requires 1 byte of memory. Operators C has rich set of operators. An operator is defined as a symbol that specifies an operation to be performed. Operators inform the computer what tasks it has to perform as well as the order in which to perform them. The order in which operations are performed is called the order of precedence. It is also called hierarchy. The direction in which operations are carried out is called associativity. There are three types of operators in C.  Unary operators  Binary operators  Ternary operator Unary Operators Order of precedence is high for the unary operators and they have only one operand. The order of evaluation (associativity) is from right to left. The increment (++) or decrement (--) operator is used to increase or to decrease the current value of a variable by 1. Generally the unary operators appear before the operand. There are two forms: Postfix increment or decrement Prefix increment or decrement Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 3
  • 4. The unary operators ++ and -- are called prefix increment or decrement operators when they appear before the operand. The unary operators ++ and -- are called postfix increment or decrement operators when they appear after the operand. Binary Operators Arithmetic Operators The arithmetic operators +, -, *, /, and % are binary operators as they have two operands. All the arithmetic operators observe left to right associativity. The arithmetic operators can be used with integers and float values. The modulus operator works with integers only and it gives the remainder value after division. Relational Operators The relational or Boolean operators are binary operators as they always have two operands. All the relational operators observe left to right associativity, that is, they are evaluated from left to right. Logical Operators The logical operators “&&” and “||” are used to connect two or more relational expressions. The “&&” operator is the logical AND operator and it returns a value of true if both of its operands evaluate to true. A value of false is returned if one or both of its operands evaluate to false. The logical OR operator “||” returns a value of true when one or both of its operands evaluates to true and a value of false when both of its operands evaluate to false. Assignment Operators The assignment operator (=) assigns the value of the right-hand operand to the left-hand operand. C has arithmetic-assignment operators too. They are +=, - =, *=, /= and %=. Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 4
  • 5. Consider the following statement: i = i + 1; Here, the old value of the variable i is incremented by 1 and the incremented value is stored as the new value of i. The above statement can be represented in the following ways. Using the arithematic - assignment operator, i += 1; In the above statement, the operator += is used to increment the old value of i by one and the new value is stored in the variable I itself. Similarly, the statement i *= 2; represents that the old value of i is multiplied by 2 and the new value is stored in i itself. The order of evaluation Using the precedence of operators, we will see how to evaluate an expression. The bracketed expression should be evaluated first. Consider the following expression 5 * 2 + 8 + (3 – 2) * 5 It will be evaluated as follows: 5*2+8+1*5 (bracketed expression is evaluated first) 10 + 8 + 5 (multiplication has higher precedence over addition) 23 (the value of the expression is 23) Ternary Operator C has one ternary operator, which is a conditional operator. The symbol used for this operator is ?: and it has three operands. The syntax of the conditional operator is as follows: conditional expression? expression 1 : expression 2; If the conditional expression is true, expression 1 is evaluated. If the conditional expression is false, expression 2 is evaluated. Example : The following example show the uses of conditional operator: c = (a > b) ? a : b; If a is greater than b, the value of a is assigned to c else the value of b is assigned to c. Punctuations C’s punctuation symbols and their uses are listed as follows: [] - used to represent array index (square brackets) {} - used to cover the body of the function (curly braces) () - used to represent a function, to group items and to group expressions (simple parentheses) <> - used to enclose a header file in a preprocessor statement (angular brackets) ““ - used to represent string literals (double quotes) ‘‘ - used to represent a character constant (single quotes) Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 5
  • 6. /* */ - used to represent a comment ; - used as a statement terminator , - used to separate items blank and white space – used to improve readability of the program. Structure of C Program A program is defined as a set of instructions to be executed sequentially to obtain the desired result. A function is a program, which is being used to carry out some small task. C programs can be very small. C programs are made up of functions. A program cannot be written without a function. A function may be pre-defined or user-defined. # include <stdio.h> main() { printf(“Welcome to C Programming”); } This program, upon execution, will display the message Welcome to C Programming on the screen. The user has to define the main() function to provide necessary code. When a C program runs, the control is transferred to this function. This is called the program’s entry point. The program has two functions, one is the user-defined main() function which is the entry point and the other one is printf() function which is pre-defined and used to display the results on the standard output (screen or monitor). Simple parentheses () are used to represent a function. Here main() is the calling function and printf() is the called function. The first line in the program # include <stdio.h> is a preprocessor statement. #include is a preprocessor directive. The preprocessor is a software program that will expand the source code while the program is compiled. The #include <stdio.h> statement includes the contents of the stdio.h file (standard input and output header file) globally, that is, prior to the main() function. The contents of the stdio.h file are the function declaration statements of the pre-defined output and input functions like printf() and scanf() etc. Statements Each and every line of a C program can be considered as a statement. There are generally four types of statements. They are:  Preprocessor statement  Function header statement  Declaration statement  Executable statement As you know already, the preprocessor statement is used to expand the source code by including the function declaration statements from the specified header files. The function header statement is used as a first line in the definition of a function. The declaration statements are further classified into variable declaration statements and function declaration statements. Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 6
  • 7. Input and Output Statements The function printf() is used to display the results on the standard output (screen). We have seen the use of printf() to display the string on the monitor. Actually, the first parameter of the printf() function is a string which is used to control the output and, hence it can be called as “control string”. This parameter is used to format the output for display and hence we can also call it as a “formatting string”. Example: To print a value of an integer: int n; /* variable n is declared as integer*/ n = 10; printf(“%d”, n); In the above example, ‘%d’ is used as a formatting character within the control string of printf() function to display the value of an integer. The control string of printf() function can take three types of characters.  Ordinary characters  Formatting characters  Escape sequence characters Ordinary characters within the control string are displayed as such. In the case of printf(“hello”); statement, the control string has ordinary characters only. They are displayed as such on the screen. The following table lists the formatting characters used to display the values of various types. Input from keyboard To read a value from the keyboard (standard input), the function scanf() is used. The code segment to read a value for an integer variable x is given below: int x; scanf(“%d”, &x); While the scanf() function is being executed, the system waits for the user’s input. The user has to provide data through keyboard. The data will be placed in the location of x only after “Enter” key is pressed in the keyboard. The second parameter of the above scanf() function is &x, which represents the address of x. & is the address of operator and when it is being used with a variable, it provides the address of that variable. Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 7
  • 8. Lab Exercises 1. Write a C program to display a message “Welcome to C programming”. # include <stdio.h> # include <conio.h> main() { clrscr(); printf(“Welcome to C programming”); getch(); } 2. Write a C program to find the sum of 2 numbers. # include <stdio.h> # include <conio.h> main() { int a,b,c; printf(“nEnter any 2 numbers:”); scanf(“%d %d”,&a,&b); c=a+b; printf(“nSum of 2 nos=%d”,c); getch(); } 3. Write a C program to find the area of rectangle. # include <stdio.h> # include <conio.h> main() { float a,l,b; printf(“nEnter Length & Breadth:”); scanf(“%f %f”,&l,&b); a=l*b; printf(“nArea of Rectangle=%f”,a); getch(); } Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 8
  • 9. 4. Write a C program to calculate simple interest. # include <stdio.h> # include <conio.h> main() { float p,n,r,si; printf(“nEnter values of P,N & R:”); scanf(“%f %f %f”,&p,&n,&r); si=(p*n*r)/100; printf(“nSimple Interest=%f”,si); getch(); } 5. Write a C program to find the area of triangle. # include <stdio.h> # include <conio.h> main() { float a,b,h; printf(“nEnter Base & Height:”); scanf(“%f %f”,&b,&h); a=0.5*b*h; printf(“nArea of Triangle=%f”,a); getch(); } Question Bank 2 mark questions: 1. Write a short note on C Programming. 2. What are tokens ? Name them. 3. Write a note on Character Set. 4. Define constants. 5. What are the types of constants ? 6. What do you mean by integer constants ? 7. Write a note on floating point constants. 8. What are character constants ? Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 9
  • 10. 9. Define escape sequence. 10. Write a note on String literal. 11. Define identifiers. 12. Define operator in C. 13. What is hierarchy ? 14. Define associativity. 15. What are the types of operators ? 16. Write a note on Unary operators. 17. Write a note on Arithmetic operators in C. 18. What are the relational operators in C. 19. Write a note on logical operators. 20. What is the purpose of Assignment operator in C. 21. What are the types of statements used in C. 22. Write a C program to display a message “Welcome to C programming”. 23. List down the formatting characters used to display the values of various types. 5 mark questions: 1. What are the features of C language ? 2. Write a note on escape sequences in C language. 3. List down the rules to name a variable in C. 4. Explain the fundamental data types in C programming. 5. Explain the order of evaluation in C with an example. 6. Explain conditional operator with an example. 7. Explain printf statement in C language. 8. How do you input data from keyboard ? 9. Write a C program to find the sum of 2 numbers. 10. Write a C program to find the area of rectangle. 11. Write a C program to calculate simple interest. 12. Write a C program to find the area of triangle. 8 mark questions: 1. Explain the types of constants in C language. 2. Explain Binary operators in C. 3. Explain the structure of C program. 4. Explain the punctuation symbols used in C language. ************************* Class 8 | C programming | III Term | R. Andrew, M.Sc[IT], M.C.A, M.Phil 10