SlideShare a Scribd company logo
KHANAL PRALHAD
Navodit , Samakhusi, Kathmandu
Structure of C programming
C programming
Header Files and C pre-processors
Header Files:
 A header file is a file containing C declarations and macro definitions to be
shared between several source files. You request the use of a header file in your
program by including it, with the C pre-processing directive ‘#include’.
 The usual convention is to give header files names that end with .h
 For example:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI
#define area 100
Pre-Processors:
 Is a macro processor that is used automatically by the C compiler to
transform your program before actual compilation (Pre-processor directives
are executed before compilation.).
 It is called a macro processor because it allows you to define macros, which
are brief abbreviations for longer constructs. Macro is defined by #define
directive.
 Pre-processing directives are lines in your program that start with #. For
example, #define is the directive that defines a macro. Whitespace is also
allowed before and after the #.
 For Examples:
#include
#define, etc.
Assignment 1
• What is pre-processor? List any two pre-processor.
• Write down the importance of header files and explain about any
three of them .
4.2 Fundamentals of C
Character Set
• As every language contains a set of characters used to construct words, statements,
etc., C language also has a set of characters which include alphabets, digits, and
special symbols. C language supports a total of 256 characters.
• Every C program contains statements. These statements are constructed using
words and these words are constructed using characters from C character set. C
language character set contains the following set of characters...
1. Alphabets/Letters
2. Digits
3. Special Symbols
1. Alphabets
C language supports all the alphabets from the English language. Lower and upper
case letters together support 52 alphabets.
lower case letters - a to z
UPPER CASE LETTERS - A to Z
2. Digits
C language supports 10 digits which are used to construct numerical values in C
language.
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
3. Special Symbols
C language supports a rich set of special symbols that include symbols to perform
mathematical operations, to check conditions, white spaces, backspaces, and other
special symbols.
Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , <  | tab newline
space NULL bell backspace vertical tab etc.,
Use of Comments
• They are ignored by the compiler
• This section is used to provide a small description of the program. The
comment lines are simply ignored by the compiler, that means they are not
executed.
• In C, there are two types of comments.
(a) Single Line Comments: Single line comment begins with // symbol. We can
write any number of single line comments.
(b) Multiple Lines Comments: Multiple lines comment begins with /* symbol
and ends with */. We can write any number of multiple lines comments in a
program.
• The comment lines are optional. Based on the requirement, we write comments.
All the comment lines in a C program just provide the guidelines to understand the
program and its code.
For Example
// C program to illustrate use of single-line comment
#include <stdio.h>
int main()
{
// Single line comment
printf("Welcome to Online Classes");
getch();
}
For Example
/* C program to illustrate
use of multi-line comment */
#include <stdio.h>
int main()
{
/* Multi-line comment
written to demonstrate comments
in C */
printf("Welcome to Online Class");
getch();
}
Statements: Simple and Compound
Simple Statements:
 is an expression (followed by a semicolon, the terminator for all simple statements). Its value is computed and
discarded.
 For example
#include <stdio.h>
int main()
{
int x, y, z;
printf("Enter two numbers to addn");
scanf("%d%d", &x, &y);
z = x + y;
printf("Sum of the numbers = %dn", z);
return 0;}
 Other examples of simple statements are the jump statements return, break, continue, and goto.
Compound Statements
• Several individual statements enclosed in a pair of braces {}.
• It provides capabilities for enabling statements within other statements.
if(houseIsOnFire) {
/* ouch! */
scream();
runAway();
}
• Compound statements come in two varieties: conditionals and loops.
Example
#include <stdio.h>
int main () {
int a;
/* for loop execution */
for( a = 10; a < 20; a = a + 1 ){
printf("value of a: %dn", a);
}
return 0;
}
C programming
4.3 Operators and Expressions
Operators
• Arithmetical Operator(Binary Operator)
• Relational Operator(Comparison Operator)
• Logical Operator(Boolean Operator)
• Assignment Operator
• Unary Operator(Increment/decrement Operator)
• Conditional Operators(Ternary Operator)
• Comma Operators
• Size of Operator
Type Casting And
Conversion
 The type conversion is the
process of converting a
data value from one data
type to another data type
automatically by the
compiler.
 Sometimes type conversion is
also called implicit type
conversion. The implicit type
conversion is automatically
performed by the compiler.
C programming
Type Casting And
Conversion
 Typecasting is also called an
explicit type conversion.
Compiler converts data from one
data type to another data type
implicitly.
 When compiler converts
implicitly, there may be a data
loss. In such a case, we convert
the data from one data type to
another data type using
explicit type conversion.
 Also termed as local
conversion.
4.4 Input/Output (I/O) Functions
Write a c program to add two numbers.
Write a c program to input four numbers and find their average and sum
Write a c program to add two numbers using both implicit and explicit method.
Write a c program to define compound statement.
WAP to find square of numbers.
WAP to calculate cube of number.
WAP to calculate area and circumference of circle.
WAP to find area and perimeter of rectangle
WAP to calculate distance using S= 𝑢𝑡 + 1/2𝑎𝑡2
WAP to find SI and A.
Write a c program to input four numbers and find their average
and sum
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,d,sum,avg;
printf("enter four numbers");
scanf("%d%d%d%d",&a,&b,&c,&d);
sum=a+b+c+d;
printf("sum is %d: ", sum);
avg=(sum)/4;
printf("average is %d ",avg);
getch();
}
Write a c program to add two numbers.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,sum;
printf("enter two numbers");
scanf("%d%d",&a,&b);
sum=a+b;
printf("sum is %d: ", sum);
getch();
}
Write a c program to add two numbers using implicit method.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
float sum;
printf("enter two numbers");
scanf("%d%d",&a,&b);
sum=a+b;
printf("sum is %f: ", sum);
getch();
}
Write a c program to add two numbers using explicit method.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
float sum;
printf("enter two numbers");
scanf("%d%d",&a,&b);
sum=(float)a+b;
printf("sum is %f: ", sum);
getch();
}
Differentiate between printf() and scanf()
Printf() Scanf()
Ternary Operator
 Ternary operator allows executing different code depending on the
value of a condition, and the result of the expression is the returned
value of the executed code.
 The main advantage of using ternary operator is to reduce the
number of line codes and improve the performance of application.
#include<stdio.h>
int main()
{
int a,b;
printf("Enter any two numbers n");
scanf("%d%d", &a , &b);
if(a>b) {
printf("%d",a);
printf(" is largest number of given
numbers n"); }
else{
printf("%d",b);
printf(" is largest number of given
numbers n"); }
return 0;
}
#include<stdio.h>
int main() {
int a, b, max;
printf("Enter any two numbers
n");
scanf("%d%d", & a, & b);
max = (a > b) ? a : b;
printf("%d", max);
printf("is the largest number of
given numbers");
return 0;
}
4.5 Control Structure
If cost price and selling price of an item is input through the keyboard,
WAP to determine whether the seller has made profit or incurred loss. Also
determine how much profit he made or loss be incurred.
#include<stdio.h>
#include<conio.h>
void main()
{
int cp,sp,tl,tp;
printf("Enter the Cost pricen");
scanf("%d",&cp);
printf("Enter the Selling pricen");
scanf("%d",&sp);
if(sp>cp)
{
tp=sp-cp;
printf("The profit is %d",tp);
}
else if (sp<cp)
{
tl=cp-sp;
printf("The loss is %d",tl);
}
else
printf("There is neither profit nor loss");
}
Control structure
• Are those programming constructs that controls the flow of programming
statements.
• It specifies the order of statements in the program.
• Are of three types.
C programming
A. Decision making(Selective/Branching) Control Structure
a) Conditional Statements
Are those statements that makes decision based on the condition and its
outcome.
Are of different forms
i. If Statement
ii. If else statement
iii. If else if statement(if-else ladder)
iv. Nested if else statement
a) Switch-Case Statements
It makes decision based upon the value of expression which is included in
the switch statement and branches.
C programming
i. If Statement
• if statement is used to verify the given condition and executes the
block of statements based on the condition result.
• The simple if statement evaluates specified condition.
• If it is TRUE, it executes the next statement or block of statements. If
the condition is FALSE, it skips the execution of the next statement or
block of statements.
• Simple if statement is used when we have only one option that is
executed or skipped based on a condition.
C programming
C programming
// Program to check given number is divisible by 5 or not
#include<stdio.h>
#include<conio.h>
void main(){
int n ;
printf("Enter any integer number: ") ;
scanf("%d", &n) ;
if ( n%5 == 0 )
printf("Given number is divisible by 5n") ;
printf("statement does not belong to if!!!") ;
getch();
}
1. WAP to check given number is positive or not.
2. WAP to check whether the given number is even or not.
3. WAP to check whether the given number is divisible by 10 or
not.
4. WAP to check whether the given number is 3 or not.
ii. If else statement
• The if-else statement is used to verify the given condition and executes
only one out of the two blocks of statements based on the condition
result.
• The if-else statement evaluates the specified condition.
• If it is TRUE, it executes a block of statements (True block). If the
condition is FALSE, it executes another block of statements (False
block).
• The if-else statement is used when we have two options and only
one option has to be executed based on a condition result (TRUE
or FALSE).
C programming
// To Test whether given number is even or odd.
#include<stdio.h>
#include<conio.h>
void main(){
int n ;
printf("Enter any integer number: ") ;
scanf("%d", &n) ;
if ( n%2 == 0 )
printf("Given number is EVENn") ;
else
printf("Given number is ODDn") ;
}
1. WAP to read two numbers and display smallest one.
2. WAP to check given number is odd or even.
3. WAP to check given number is positive or negative.
4. WAP to check given number is divisible by 5 and not by
10.
iii. If else if statement(if else ladder)
• Writing a if statement inside else of an if statement is called if-else-if statement.
• The if-else-if statement can be defined using any combination of simple if & if-
else statements.
• Conditions are checked from top of the ladder to downwards. As soon as the true
conditions are found, the statements associated with it are executed and the control
is transferred to outside of the ladder skipping the remaining part of the ladder.
C programming
C programming
#include<stdio.h>
#include<conio.h>
void main(){
int a, b, c ; // largest of three numbers
printf("Enter any three integer numbers: ") ;
scanf("%d%d%d", &a, &b, &c) ;
if( a>=b && a>=c)
printf("%d is the largest number", a) ;
else if (b>=c)
printf("%d is the largest number", b) ;
else
printf("%d is the largest number", c) ;
}
1. WAP to find the largest among four
numbers.
2. WAP to find smallest among four numbers.
3. WAP to check whether the given number is
positive, negative or zero.
iv. Nested if else statement
• Writing a if statement inside another if statement is called nested if statement.
• The if-else-if statement can be defined using any combination of simple if & if-
else statements.
• IT is used when a condition is to be checked inside another condition at a time in
the same program to make decision.
C programming
C programming
#include<stdio.h>
#include<conio.h>
void main(){
int n ;
printf("Enter any integer number: ") ;
scanf("%d", &n) ;
if ( n < 100 ) //nested if else statement checking odd or even
{
printf("Given number is below 100n") ;
if( n%2 == 0)
printf("And it is EVEN") ;
else
printf("And it is ODD") ;
}
else
printf("Given number is not below 100") ;
}
b. Switch Case Statements
• the number of options increases, the complexity of the program also gets
increased.
• This type of problem can be solved very easily using a switch statement. Using the
switch statement, one can select only one option from more number of options
very easily.
• In the switch statement, we provide a value that is to be compared with a value
associated with each option. Whenever the given value matches the value
associated with an option, the execution starts from that option.
• In the switch statement, every option is defined as a case.
C programming
 The switch statement contains one or more cases and each case has a value
associated with it.
 At first switch statement compares the first case value with the switchValue,
if it gets matched the execution starts from the first case. If it doesn't match
the switch statement compares the second case value with the switchValue
and if it is matched the execution starts from the second case. This process
continues until it finds a match.
 If no case value matches with the switchValue specified in the switch
statement, then a special case called default is executed.
 When a case value matches with the switchValue, the execution starts from
that particular case.
 This execution flow continues with the next case statements also. To avoid
this, we use the "break" statement at the end of each case. That means the
break statement is used to terminate the switch statement. However, it is
optional.
#include<stdio.h>
#include<conio.h>
int main(){
int n ;
printf("Enter any digit: ") ;
scanf("%d", &n) ;
switch( n )
{
case 0: printf("ZERO") ;
break ;
case 1: printf("ONE") ;
break ;
case 2: printf("TWO") ;
break ;
case 3: printf("THREE") ;
break ;
case 4: printf("FOUR") ;
break ;
case 5: printf("FIVE") ;
break ;
case 6: printf("SIX") ;
break ;
case 7: printf("SEVEN") ;
break ;
case 8: printf("EIGHT") ;
break ;
case 9: printf("NINE") ;
break ;
default: printf("Not a Digit") ;
}
getch() ;
}
1. WAP to display the name of the day in a week, using switch case
statement.
2. WAP to display the names of the month in a year, using switch
case statements.
3. WAP to read any two integer values from users and calculate sum,
difference, and product using seitch case.
C programming
C programming

More Related Content

PPTX
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
PPT
Unit 4 Foc
JAYA
 
PDF
C programming
saniabhalla
 
PPT
C the basic concepts
Abhinav Vatsa
 
PPT
Introduction to Basic C programming 01
Wingston
 
PPT
Structure of a C program
David Livingston J
 
PPTX
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .
 
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
Unit 4 Foc
JAYA
 
C programming
saniabhalla
 
C the basic concepts
Abhinav Vatsa
 
Introduction to Basic C programming 01
Wingston
 
Structure of a C program
David Livingston J
 
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .
 

What's hot (20)

PDF
Top C Language Interview Questions and Answer
Vineet Kumar Saini
 
PPTX
Programming in C Basics
Bharat Kalia
 
PDF
Casa lab manual
BHARATNIKKAM
 
ODP
OpenGurukul : Language : C Programming
Open Gurukul
 
PPSX
Complete C programming Language Course
Vivek Singh Chandel
 
ODP
CProgrammingTutorial
Muthuselvam RS
 
PPTX
Basic c programming and explanation PPT1
Rumman Ansari
 
PPT
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
DOC
C notes for exam preparation
Lakshmi Sarvani Videla
 
PDF
best notes in c language
India
 
PPTX
C languaGE UNIT-1
Malikireddy Bramhananda Reddy
 
PPTX
Structure of c_program_to_input_output
Anil Dutt
 
PDF
C language for Semester Exams for Engineers
Appili Vamsi Krishna
 
PPTX
C Programming Unit-1
Vikram Nandini
 
PPT
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
PDF
Learning c - An extensive guide to learn the C Language
Abhishek Dwivedi
 
PPTX
C Language (All Concept)
sachindane
 
DOC
Cnotes
Muthuganesh S
 
Top C Language Interview Questions and Answer
Vineet Kumar Saini
 
Programming in C Basics
Bharat Kalia
 
Casa lab manual
BHARATNIKKAM
 
OpenGurukul : Language : C Programming
Open Gurukul
 
Complete C programming Language Course
Vivek Singh Chandel
 
CProgrammingTutorial
Muthuselvam RS
 
Basic c programming and explanation PPT1
Rumman Ansari
 
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
C notes for exam preparation
Lakshmi Sarvani Videla
 
best notes in c language
India
 
Structure of c_program_to_input_output
Anil Dutt
 
C language for Semester Exams for Engineers
Appili Vamsi Krishna
 
C Programming Unit-1
Vikram Nandini
 
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Learning c - An extensive guide to learn the C Language
Abhishek Dwivedi
 
C Language (All Concept)
sachindane
 
Ad

Similar to C programming (20)

PPT
Unit i intro-operators
HINAPARVEENAlXC
 
PPT
Introduction to C
Janani Satheshkumar
 
PPTX
CHARACTERISTICS OF C (1).pptxtejwueghhehe
hboi8164
 
PPT
c-programming
Zulhazmi Harith
 
PPTX
basic C PROGRAMMING for first years .pptx
divyasindhu040
 
PDF
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
PPT
Chap 1 and 2
Selva Arrunaa Mathavan
 
PPTX
Introduction to c programming
Alpana Gupta
 
PPTX
C introduction
AswathyBAnil
 
PPTX
comp 122 Chapter 2.pptx,language semantics
floraaluoch3
 
PPTX
C Programming - Basics of c -history of c
DHIVYAB17
 
PPTX
c programming session 1.pptx
RSathyaPriyaCSEKIOT
 
PPTX
C programming language
Abin Rimal
 
PPTX
c
rama sudha
 
PDF
qb unit2 solve eem201.pdf
Yashsharma304389
 
PPTX
Cpu
Mohit Jain
 
PPTX
What is c
Nitesh Saitwal
 
PPTX
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
bayazidalom983
 
PPTX
Introduction to C Programming
Aniket Patne
 
PPT
424769021-1-First-C-Program-1-ppt (1).ppt
advRajatSharma
 
Unit i intro-operators
HINAPARVEENAlXC
 
Introduction to C
Janani Satheshkumar
 
CHARACTERISTICS OF C (1).pptxtejwueghhehe
hboi8164
 
c-programming
Zulhazmi Harith
 
basic C PROGRAMMING for first years .pptx
divyasindhu040
 
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
Introduction to c programming
Alpana Gupta
 
C introduction
AswathyBAnil
 
comp 122 Chapter 2.pptx,language semantics
floraaluoch3
 
C Programming - Basics of c -history of c
DHIVYAB17
 
c programming session 1.pptx
RSathyaPriyaCSEKIOT
 
C programming language
Abin Rimal
 
qb unit2 solve eem201.pdf
Yashsharma304389
 
What is c
Nitesh Saitwal
 
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
bayazidalom983
 
Introduction to C Programming
Aniket Patne
 
424769021-1-First-C-Program-1-ppt (1).ppt
advRajatSharma
 
Ad

Recently uploaded (20)

PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Landforms and landscapes data surprise preview
jpinnuck
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 

C programming

  • 1. KHANAL PRALHAD Navodit , Samakhusi, Kathmandu
  • 2. Structure of C programming
  • 4. Header Files and C pre-processors Header Files:  A header file is a file containing C declarations and macro definitions to be shared between several source files. You request the use of a header file in your program by including it, with the C pre-processing directive ‘#include’.  The usual convention is to give header files names that end with .h  For example: #include<stdio.h> #include<conio.h> #include<math.h> #define PI #define area 100
  • 5. Pre-Processors:  Is a macro processor that is used automatically by the C compiler to transform your program before actual compilation (Pre-processor directives are executed before compilation.).  It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs. Macro is defined by #define directive.  Pre-processing directives are lines in your program that start with #. For example, #define is the directive that defines a macro. Whitespace is also allowed before and after the #.  For Examples: #include #define, etc.
  • 6. Assignment 1 • What is pre-processor? List any two pre-processor. • Write down the importance of header files and explain about any three of them .
  • 8. Character Set • As every language contains a set of characters used to construct words, statements, etc., C language also has a set of characters which include alphabets, digits, and special symbols. C language supports a total of 256 characters. • Every C program contains statements. These statements are constructed using words and these words are constructed using characters from C character set. C language character set contains the following set of characters... 1. Alphabets/Letters 2. Digits 3. Special Symbols
  • 9. 1. Alphabets C language supports all the alphabets from the English language. Lower and upper case letters together support 52 alphabets. lower case letters - a to z UPPER CASE LETTERS - A to Z 2. Digits C language supports 10 digits which are used to construct numerical values in C language. Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 3. Special Symbols C language supports a rich set of special symbols that include symbols to perform mathematical operations, to check conditions, white spaces, backspaces, and other special symbols. Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , < | tab newline space NULL bell backspace vertical tab etc.,
  • 10. Use of Comments • They are ignored by the compiler • This section is used to provide a small description of the program. The comment lines are simply ignored by the compiler, that means they are not executed. • In C, there are two types of comments. (a) Single Line Comments: Single line comment begins with // symbol. We can write any number of single line comments. (b) Multiple Lines Comments: Multiple lines comment begins with /* symbol and ends with */. We can write any number of multiple lines comments in a program. • The comment lines are optional. Based on the requirement, we write comments. All the comment lines in a C program just provide the guidelines to understand the program and its code.
  • 11. For Example // C program to illustrate use of single-line comment #include <stdio.h> int main() { // Single line comment printf("Welcome to Online Classes"); getch(); }
  • 12. For Example /* C program to illustrate use of multi-line comment */ #include <stdio.h> int main() { /* Multi-line comment written to demonstrate comments in C */ printf("Welcome to Online Class"); getch(); }
  • 13. Statements: Simple and Compound Simple Statements:  is an expression (followed by a semicolon, the terminator for all simple statements). Its value is computed and discarded.  For example #include <stdio.h> int main() { int x, y, z; printf("Enter two numbers to addn"); scanf("%d%d", &x, &y); z = x + y; printf("Sum of the numbers = %dn", z); return 0;}  Other examples of simple statements are the jump statements return, break, continue, and goto.
  • 14. Compound Statements • Several individual statements enclosed in a pair of braces {}. • It provides capabilities for enabling statements within other statements. if(houseIsOnFire) { /* ouch! */ scream(); runAway(); } • Compound statements come in two varieties: conditionals and loops.
  • 15. Example #include <stdio.h> int main () { int a; /* for loop execution */ for( a = 10; a < 20; a = a + 1 ){ printf("value of a: %dn", a); } return 0; }
  • 17. 4.3 Operators and Expressions
  • 18. Operators • Arithmetical Operator(Binary Operator) • Relational Operator(Comparison Operator) • Logical Operator(Boolean Operator) • Assignment Operator • Unary Operator(Increment/decrement Operator) • Conditional Operators(Ternary Operator) • Comma Operators • Size of Operator
  • 19. Type Casting And Conversion  The type conversion is the process of converting a data value from one data type to another data type automatically by the compiler.  Sometimes type conversion is also called implicit type conversion. The implicit type conversion is automatically performed by the compiler.
  • 21. Type Casting And Conversion  Typecasting is also called an explicit type conversion. Compiler converts data from one data type to another data type implicitly.  When compiler converts implicitly, there may be a data loss. In such a case, we convert the data from one data type to another data type using explicit type conversion.  Also termed as local conversion.
  • 23. Write a c program to add two numbers. Write a c program to input four numbers and find their average and sum Write a c program to add two numbers using both implicit and explicit method. Write a c program to define compound statement. WAP to find square of numbers. WAP to calculate cube of number. WAP to calculate area and circumference of circle. WAP to find area and perimeter of rectangle WAP to calculate distance using S= 𝑢𝑡 + 1/2𝑎𝑡2 WAP to find SI and A.
  • 24. Write a c program to input four numbers and find their average and sum #include<stdio.h> #include<conio.h> int main() { int a,b,c,d,sum,avg; printf("enter four numbers"); scanf("%d%d%d%d",&a,&b,&c,&d); sum=a+b+c+d; printf("sum is %d: ", sum); avg=(sum)/4; printf("average is %d ",avg); getch(); }
  • 25. Write a c program to add two numbers. #include<stdio.h> #include<conio.h> int main() { int a,b,sum; printf("enter two numbers"); scanf("%d%d",&a,&b); sum=a+b; printf("sum is %d: ", sum); getch(); }
  • 26. Write a c program to add two numbers using implicit method. #include<stdio.h> #include<conio.h> int main() { int a,b; float sum; printf("enter two numbers"); scanf("%d%d",&a,&b); sum=a+b; printf("sum is %f: ", sum); getch(); }
  • 27. Write a c program to add two numbers using explicit method. #include<stdio.h> #include<conio.h> int main() { int a,b; float sum; printf("enter two numbers"); scanf("%d%d",&a,&b); sum=(float)a+b; printf("sum is %f: ", sum); getch(); }
  • 28. Differentiate between printf() and scanf() Printf() Scanf()
  • 30.  Ternary operator allows executing different code depending on the value of a condition, and the result of the expression is the returned value of the executed code.  The main advantage of using ternary operator is to reduce the number of line codes and improve the performance of application.
  • 31. #include<stdio.h> int main() { int a,b; printf("Enter any two numbers n"); scanf("%d%d", &a , &b); if(a>b) { printf("%d",a); printf(" is largest number of given numbers n"); } else{ printf("%d",b); printf(" is largest number of given numbers n"); } return 0; } #include<stdio.h> int main() { int a, b, max; printf("Enter any two numbers n"); scanf("%d%d", & a, & b); max = (a > b) ? a : b; printf("%d", max); printf("is the largest number of given numbers"); return 0; }
  • 33. If cost price and selling price of an item is input through the keyboard, WAP to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss be incurred.
  • 34. #include<stdio.h> #include<conio.h> void main() { int cp,sp,tl,tp; printf("Enter the Cost pricen"); scanf("%d",&cp); printf("Enter the Selling pricen"); scanf("%d",&sp); if(sp>cp) { tp=sp-cp; printf("The profit is %d",tp); } else if (sp<cp) { tl=cp-sp; printf("The loss is %d",tl); } else printf("There is neither profit nor loss"); }
  • 35. Control structure • Are those programming constructs that controls the flow of programming statements. • It specifies the order of statements in the program. • Are of three types.
  • 37. A. Decision making(Selective/Branching) Control Structure a) Conditional Statements Are those statements that makes decision based on the condition and its outcome. Are of different forms i. If Statement ii. If else statement iii. If else if statement(if-else ladder) iv. Nested if else statement a) Switch-Case Statements It makes decision based upon the value of expression which is included in the switch statement and branches.
  • 39. i. If Statement • if statement is used to verify the given condition and executes the block of statements based on the condition result. • The simple if statement evaluates specified condition. • If it is TRUE, it executes the next statement or block of statements. If the condition is FALSE, it skips the execution of the next statement or block of statements. • Simple if statement is used when we have only one option that is executed or skipped based on a condition.
  • 42. // Program to check given number is divisible by 5 or not #include<stdio.h> #include<conio.h> void main(){ int n ; printf("Enter any integer number: ") ; scanf("%d", &n) ; if ( n%5 == 0 ) printf("Given number is divisible by 5n") ; printf("statement does not belong to if!!!") ; getch(); }
  • 43. 1. WAP to check given number is positive or not. 2. WAP to check whether the given number is even or not. 3. WAP to check whether the given number is divisible by 10 or not. 4. WAP to check whether the given number is 3 or not.
  • 44. ii. If else statement • The if-else statement is used to verify the given condition and executes only one out of the two blocks of statements based on the condition result. • The if-else statement evaluates the specified condition. • If it is TRUE, it executes a block of statements (True block). If the condition is FALSE, it executes another block of statements (False block). • The if-else statement is used when we have two options and only one option has to be executed based on a condition result (TRUE or FALSE).
  • 46. // To Test whether given number is even or odd. #include<stdio.h> #include<conio.h> void main(){ int n ; printf("Enter any integer number: ") ; scanf("%d", &n) ; if ( n%2 == 0 ) printf("Given number is EVENn") ; else printf("Given number is ODDn") ; }
  • 47. 1. WAP to read two numbers and display smallest one. 2. WAP to check given number is odd or even. 3. WAP to check given number is positive or negative. 4. WAP to check given number is divisible by 5 and not by 10.
  • 48. iii. If else if statement(if else ladder) • Writing a if statement inside else of an if statement is called if-else-if statement. • The if-else-if statement can be defined using any combination of simple if & if- else statements. • Conditions are checked from top of the ladder to downwards. As soon as the true conditions are found, the statements associated with it are executed and the control is transferred to outside of the ladder skipping the remaining part of the ladder.
  • 51. #include<stdio.h> #include<conio.h> void main(){ int a, b, c ; // largest of three numbers printf("Enter any three integer numbers: ") ; scanf("%d%d%d", &a, &b, &c) ; if( a>=b && a>=c) printf("%d is the largest number", a) ; else if (b>=c) printf("%d is the largest number", b) ; else printf("%d is the largest number", c) ; }
  • 52. 1. WAP to find the largest among four numbers. 2. WAP to find smallest among four numbers. 3. WAP to check whether the given number is positive, negative or zero.
  • 53. iv. Nested if else statement • Writing a if statement inside another if statement is called nested if statement. • The if-else-if statement can be defined using any combination of simple if & if- else statements. • IT is used when a condition is to be checked inside another condition at a time in the same program to make decision.
  • 56. #include<stdio.h> #include<conio.h> void main(){ int n ; printf("Enter any integer number: ") ; scanf("%d", &n) ; if ( n < 100 ) //nested if else statement checking odd or even { printf("Given number is below 100n") ; if( n%2 == 0) printf("And it is EVEN") ; else printf("And it is ODD") ; } else printf("Given number is not below 100") ; }
  • 57. b. Switch Case Statements • the number of options increases, the complexity of the program also gets increased. • This type of problem can be solved very easily using a switch statement. Using the switch statement, one can select only one option from more number of options very easily. • In the switch statement, we provide a value that is to be compared with a value associated with each option. Whenever the given value matches the value associated with an option, the execution starts from that option. • In the switch statement, every option is defined as a case.
  • 59.  The switch statement contains one or more cases and each case has a value associated with it.  At first switch statement compares the first case value with the switchValue, if it gets matched the execution starts from the first case. If it doesn't match the switch statement compares the second case value with the switchValue and if it is matched the execution starts from the second case. This process continues until it finds a match.  If no case value matches with the switchValue specified in the switch statement, then a special case called default is executed.  When a case value matches with the switchValue, the execution starts from that particular case.  This execution flow continues with the next case statements also. To avoid this, we use the "break" statement at the end of each case. That means the break statement is used to terminate the switch statement. However, it is optional.
  • 60. #include<stdio.h> #include<conio.h> int main(){ int n ; printf("Enter any digit: ") ; scanf("%d", &n) ; switch( n ) { case 0: printf("ZERO") ; break ; case 1: printf("ONE") ; break ; case 2: printf("TWO") ; break ; case 3: printf("THREE") ; break ; case 4: printf("FOUR") ; break ; case 5: printf("FIVE") ; break ; case 6: printf("SIX") ; break ; case 7: printf("SEVEN") ; break ; case 8: printf("EIGHT") ; break ; case 9: printf("NINE") ; break ; default: printf("Not a Digit") ; } getch() ; }
  • 61. 1. WAP to display the name of the day in a week, using switch case statement. 2. WAP to display the names of the month in a year, using switch case statements. 3. WAP to read any two integer values from users and calculate sum, difference, and product using seitch case.