0% found this document useful (0 votes)
106 views17 pages

Chapter - 01: "Variables, Constants & Expressions": (C - Programming)

This document provides an overview of variables, constants, and expressions in the C programming language. It discusses the history and structure of C programs. It defines different types of constants like integer, floating point, character, and string constants. It also describes variables, identifiers, and keywords. Finally, it covers different types of operators used in C like arithmetic, relational, logical, ternary, and increment/decrement operators.

Uploaded by

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

Chapter - 01: "Variables, Constants & Expressions": (C - Programming)

This document provides an overview of variables, constants, and expressions in the C programming language. It discusses the history and structure of C programs. It defines different types of constants like integer, floating point, character, and string constants. It also describes variables, identifiers, and keywords. Finally, it covers different types of operators used in C like arithmetic, relational, logical, ternary, and increment/decrement operators.

Uploaded by

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

C-Programming

Variables, Constants and Expressions

B.Tech. 1st, 2nd, 3rd & 4th Sem, B.C.A., B.Sc. (Computers & I.T.), PGDCA,
B.Pharmacy
Teacher : Sandeep Sangwan (9417565720, 9417524702, 9463741635)
S.C.F. 204, 2nd Floor (Above Chandigarh Sweets Pvt. Ltd.), Sec-14,
Panchkula

[ C PROGRAMMING ]

Chapter - 01 : Variables, Constants


& Expressions
HISTORY OF C LANGUAGE :
Around 1960 many languages come in the field of computer like COBOL, PASCAL,
BASIC etc. At this stage programmer community started thinking that instead of learning
and using so many languages, why not use only one language, which can perform all
possible operations. An international committee was set up to develop such a language
and language named ALGOL 60 was developed. But this language was proved very
lengthy. Again a new language was developed which was called CPL (Combine
Programming Language). But this language was very specific and wast. Now another
language developed BCPL. But it also turned out to be less powerful. At the same time
Ken Thomsen wrote a language at AT&Ts Bell Labs that was called B-Language. But it
was also turned out to be very specific.
It was the Dennis Ritchie that inherited the features of B and BCPL, and added
some of his own and developed a new language C-Language. C-Language is very
powerful and compact, so it is called one-man-language.

STRUCTURE OF C PROGRAM :

#include<stdio.h>
#include<conio.h>
void main()
{
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
2

Variables, Constants and Expressions

clrscr();
printf("Hello");
getch();
}
#include : is a preprocessor directive. It is a indication for the C compiler to add
the particular header file inside the program.
stdio.h : standard input output header file
conio.h : console input output header file
void
: means empty or null. i.e. the function is not returning any value.
main( ) : is a function nessary for C program. Every C program must contain
atleast one function main().
clrscr( ) : It is a library function defined inside conio.h header file and it is used
to clear the screen.
getch( ) : This function is also a library function define inside conio.h header file
and it is used to get character from the keyboard for output.
printf( ) : Standard output function used to display given data.
{
: indicates the beginning of the function
}
: indicates the end of the function.
;
: Statement terminator used to terminate a C-statement.

C Character Set :

A Character denotes any alphabet, digit or special symbol used to represent


information. Following table shows the valid alphabets, numbers and special symbols
allowed in C:
Alphabets

Digits
Special
Symbols

A, B, C, ..,Y, Z
a, b, c,, y, z
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
~ ` ! @ # $ % ^ & * ( ) _ - + =
| \ { } [ ] : ; < > , . ? /

CONSTANTS, VARIABLES AND KEYWORDS :


The alphabets , numbers and special symbols when properly combined form
constants, variables and keywords.

CONSTANTS :

A Constant is a quantity that doesnt change. This quantity can be stored at


locations in the memory of the computer.
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
3

Variables, Constants and Expressions

Types of C Constants :
C constants can be divided into two major categories:
(a) Primary Constants
(b) Secondary Constants

These constants are further categorized as follows:


C Constants

Primary Constants

Integer Constant
Real Constant
Character Constant
String constant

Secondary Constants

Array
Pointer
Structure
Union

PRIMARY CONSTANTS :

(a) Integer constants : Integer constants are whole number without any decimal part.
Variables can be declared as integers in the following ways :
int x=5 , y=6;
short int x =3, y=10;
long int x=21 , y=636;
(b) Floating point constants : Floating point number are the numbers containing decimal
points (Real numbers). They may be written in one of the two forms called fractional form
or exponent form.
A real number in fraction form consists of signed or unsigned digits including a
decimal point between digits. The following are some real numbers in fractional form:
2.0, 17.5,
- 13.0, - 0.00625
A real number in exponent form consists of two parts : mantissa and exponent. For
instance 5.8 can be written as 0.58 x 101. The following are some real numbers in
exponent form:
152E05, 1.52E07, 0.152E08, 152.0E08, 152E+8, 1520E-04
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
4

Variables, Constants and Expressions

(c) Character constant : Character constant is single character enclosed in single


quotes, as in f. For example,
A , a , : , +
Declaration of the character variables :
char x;
char x, y, z;
The char stands for the character datatype for declaring the character constants.
(d) String constant : String constant is a sequence of zero or more characters enclosed
between double quotes. Following are some examples from string constants.
(1) The result =
(2) Rs. 2000.00
(3) This is test program by Ravi
Derived Data Types in C-Language
Type
signed char
Unsigned char
short int
or int
or short signed int
short unsigned int

Range
-128 to +127
0 to 255
-32768 to +32767

Size
1 Byte
1 Byte
2 Bytes

Format
%c
%c
%d

2 Bytes

%u

long signed int

0 to 216
i.e. 0 to 65536
-231 to (231-1)

%ld

long unsigned int

0 to (232 1)

float

-231 to (231-1)

4 Bytes
or 31 bits
4 Bytes
or 32 bits
4 Bytes

double (long float)

-263 to (263-1)

8 Bytes

%lf

long double

-279 to +(279-1)

10 Bytes

%Lf

%lu
%f

Note: - float, double and long double are always signed.


VARIABLE
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
5

Variables, Constants and Expressions

A Variable is a named location in a memory that holds a data value. The


contents of a variable can change. For example in the equation
3X + Y = 20
Since 3 and 20 cannot change, they are called constants, whereas the quantities X
& Y can vary or change hence they are called variables.
All variables must be declared before they can be used. The general form of a
variable declaration is
datatype variablename
Here datatype must be a valid data type and variablename may consist of one or
more variable names separated by commas. For example
int i , j , k ;
// Integer variables declaration
float per ;
// Floating point number variables
declaration
double balance, profit, loss ; // double variables declaration
char nm1, nm2;
// Character variables declaration
char name[100];
// String declaration
In C, the name of a variable has nothing to do with its type.
IDENTIFIER
In C, the names of variables, functions, labels and various other user-defined items are
called identifiers. The length of these identifiers can vary from one to several characters. The first
character must be a letter or an underscore, and subsequent characters must be either letters,
digits, or underscores. Some of the correct and incorrect identifier names are given below :

Correct
count
test23
high_bal

Incorrect
1count
hi!there
highbalance

In an identifier, uppercase and lowercase are treated as different. Hence, count,


Count and COUNT are three separate identifiers.
KEYWORDS

Keywords are the reserved words whose meaning has already been explained to
the C compiler. The keywords cannot be used as variable names because if we do so we
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
6

Variables, Constants and Expressions

are trying to assign a new meaning to the keyword, which is not allowed by the computer.
There are 32 keywords available in C. The complete list of keywords in C are given
below :

auto
break
case
char
const
continue
default
do

double
else
enum
extern
float
far
for
goto

if
int
long
near
register
return
short
signed

static
struct
switch
typedef
union
unsigned
void
while

OPERATORS :
An operator is a symbol or letter which causes the compiler to take an action and
yield a value. The operations being carried out are represented by operators. An operator
acts on different data items/entities called Operands.
TYPES OF OPERATORS

1.
2.
3.
4.
5.
1.

Arithmetic Operators
Relational Operators
Logical Operators
Ternary Operators
Increment and Decrement Operators
Arithmetic Operators

Arithmetic operators are those operators which perform arithmetic operations.


Arithmetic operators are considered as basic operators and known as binary operators as
they require two variables to be evaluated. For e.g. if we want to multiply two numbers,
one has to enter or feed the multiplicand and the multiplier. That is why it is considered as
a binary operator. There are mainly five types of arithmetic operators used in C language.
Operator Meaning
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
7

+
*
/
%

Variables, Constants and Expressions

Addition
Subtraction
Multiplication
Division
Modulo(Remainder of an integer division)

Addition Operator(+)
int a = 4, b = 2, c;
c = a + b;
Output : c = 6
Subtraction Operator(-)
int a = 4, b = 2, c;
c = a - b;
Output : c = 2
Multiplication Operator(*)
int a = 4, b = 2, c;
c = a * b;
Output : c = 8
Division Operator(/)
int a = 5, b = 2, c;
c = a / b;
Output : c = 2
Modulus Operator(%)
int a = 5, b = 2, c;
c = a % b;
Output : c = 1

CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
8

Variables, Constants and Expressions

Prog. 1 : A simple hello program


#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
printf("Hello to C-programming");
getch( );
}
//
: Single line comment
#include : preprocessor directive. It is an indication for the C-compiler to add the
particular header file inside C-program.
stdio.h : standard input output header file. It is used for all input output
predefined functions.
conio.h : console input output header file. It is used for all console window
related predefined functions.
void
: void means empty or null. It means that the function is not returning
any value.
main( ) : main( ) is the most important function of C-programming because the
program execution always started with main( ) function.
{
: It indicate the start of a particular block.
}
: It indicate the end of a particular block.
clrscr( ) : This function is used to clear the previous console window.
printf( ) : Standard output function.
getch( ) : This function is used to get character from keyboard
;
: Statement terminator
Prog. 2 : WAP to use special characters '\n' and '\t'
#include<stdio.h>
#include<conio.h>
void main( )
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
9

Variables, Constants and Expressions

{
clrscr( );
printf("Name : Himani Madan");
printf("\nAddress : #1261/12,Pkl");
printf("\nPhone : 9417565720");
printf("\n\nNAME\tADDRESS\t\tPHONE");
printf("\nSurbhi\t#1211/14,Pkl\t8712828");
getch( );
}
Prog. 3 : WAP for Integer Initialization
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int num = 27;
printf("Given integer is : %d",num);
getch( );
}
Prog. 4 : WAP for Integer Input from user
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int num;
printf("Enter any integer : ");
scanf("%d",&num); // & stands for memory address of variable
printf("\nGiven integer is : %d",num);
getch( );
}
Prog. 5 : WAP for Floating point number Initialization
#include<stdio.h>
#include<conio.h>
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
10

Variables, Constants and Expressions

void main( )
{
clrscr( );
float price;
price = 500.75;
printf("Given price is : %.2f",price);
getch( );
}

Prog. 6 : WAP for Floating point number Input from user


#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
float price;
printf("Enter price : ");
scanf("%f",&price);
printf("\nGiven price is : %.2f",price);
getch( );
}
Prog. 7 : WAP for character initialization
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
char ch;
ch = 'A';
printf("\nGiven character is : %c",ch);
getch( );
}
Prog. 8 : WAP for character input from user
#include<stdio.h>
#include<conio.h>
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
11

Variables, Constants and Expressions

void main( )
{
clrscr( );
char ch;
printf("Enter any character value : ");
scanf("%c",&ch);
printf("\nGiven character is : %c",ch);
getch( );
}
Prog. 9 : WAP for string initialization
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
char name[20] = "Sandeep Sangwan";
printf("%s",name);
getch( );
}
Prog. 10 : WAP for string input from user
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
char name[20];
printf("Enter name : ");
gets(name);
printf("\nMy name is : %s",name);
getch( );
}
Prog. 11 : WAP to accept two integers and display their sum, difference, product,
quotient and remainder
#include<stdio.h>
#include<conio.h>
void main()
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
12

Variables, Constants and Expressions

{
clrscr( );
int a,b;
printf("Enter two numbers : ");
scanf("%d%d",&a,&b);
printf("\nSum is : %d",a+b);
printf("\nDifference is : %d",a-b);
printf("\nProduct is : %d",a*b);
printf("\nQuotient is : %d",a/b);
printf("\nRemainder is : %d",a%b);
getch( );
}
Prog. 12 : WAP to accept the name, basic salary, HRA and DA of an employee.
Calculate and display the gross salary of employee.
gs = bs+hra+da
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
char name[20];
float bs,hra,da,gs;
printf("Enter name of employee : ");
gets(name);
printf("Enter basic salary, HRA and DA of %s : ",name);
scanf("%f%f%f",&bs,&hra,&da);
gs = bs+hra+da;
printf("\nGross salary of %s is : %.2f",name,gs);
getch( );
}
Prog. 13 : WAP to accept the name & basic salary of an employee. Calculate and
display the gross salary of employee acc. to conditions given below :
HRA = 40% of basic salary.
DA = 30% of basic salary.
gs = bs+hra+da
#include<stdio.h>
#include<conio.h>
void main( )
{
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
13

Variables, Constants and Expressions

clrscr( );
char name[20];
float bs,hra,da,gs;
printf("Enter name of employee : ");
gets(name);
printf("Enter basic salary of %s : ",name);
scanf("%f",&bs);
hra = bs*((float)40/100);
da = bs*0.3;
gs = bs+hra+da;
printf("\nGross salary of %s is : %.2f",name,gs);
getch( );
}
Prog. 14 : WAP to display the area and perimeter of a rectangle
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int l,b;
float area,perimeter;
printf("Enter length and breadth of rectangle : ");
scanf("%d%d",&l,&b);
area = l*b;
perimeter = 2*(l+b);
printf("\nArea of rectangle is : %.2f",area);
printf("\nPerimeter of rectangle is : %.2f",perimeter);
getch( );
}
Prog. 15 : WAP to display the area and circumference of a circle
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
float rad,area,cmf,pi;
pi = (float)22/7;
printf("Enter radius of circle : ");
scanf("%f",&rad);
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
14

Variables, Constants and Expressions

area = pi*rad*rad;
cmf = 2*pi*rad;
printf("\nArea of circle is : %.2f",area);
printf("\nCircumference of circle is : %.2f",cmf);
getch( );
}
Prog. 16 : WAP to accept the marks of a student in 5 different subjects and display
the aggregate and total percentage (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int eng,hin,math,sc,comp;
float agg,per;
printf("Enter marks of 5 subjects : ");
scanf("%d%d%d%d%d",&eng,&hin,&math,&sc,&comp);
agg = eng+hin+math+sc+comp;
per = agg/5;
printf("\nAggregate marks are : %.2f",agg);
printf("\nTotal percentage is : %.2f",per);
getch( );
}
Prog. 17 : Mathematical functions (Square root)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
clrscr( );
float num;
printf("Enter number : ");
scanf("%f",&num);
printf("\nSquare root of %.2f is : %.2f",num,sqrt(num));
getch( );
}
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
15

Variables, Constants and Expressions

Prog. 18 : Mathematical function (Power)


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
clrscr( );
int n,p;
printf("Enter number and its power : ");
scanf("%d%d",&n,&p);
printf("\n%d raised to the power %d is : %.2f",n,p,pow(n,p));
getch( );
}
Prog. 19 : Mathematical function (Absolute value of integer & floating pt. number)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
clrscr( );
// Absolute value of Integer
int n;
printf("Enter an integer : ");
scanf("%d",&n);
printf("\nAbsolute value of %d is : %d",n,abs(n));
// Absolute value of Floating pt. number
float num;
printf("\n\nEnter a floating pt. number : ");
scanf("%f",&num);
printf("\nAbsolute value of %.2f is : %.2f",num,fabs(num));
getch( );
}
Prog. 20 : WAP to determine the area of a triangle by using Hero's formula.
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
16

Variables, Constants and Expressions

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
clrscr( );
float a,b,c,s,area;
printf("Enter three sides of a triangle : ");
scanf("%f%f%f",&a,&b,&c);
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nArea of triangle is : %.2f",area);
getch( );
}
Prog. 21 : WAP to accept the temperature in Fahrenheit and convert it into
Centigrades
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
float f,c;
printf("Enter temperature in Fahrenheit : ");
scanf("%f",&f);
c = (f-32)/1.8;
printf("\nEqu. temperature in Centigrade is : %.2f",c);
getch( );
}
Prog. 22 : WAP to swap two numbers. (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,temp;
printf("Enter two numbers a and b : ");
scanf("%d%d",&a,&b);
CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

C-Programming
17

Variables, Constants and Expressions

printf("\nBefore swapping\n");
printf("a : %d\tb : %d",a,b);
temp=a;
a=b;
b=temp;
printf("\n\nAfter swapping\n");
printf("a : %d\tb : %d",a,b);
getch();
}

CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2ND FLOOR, SEC-14, PKL(9417565720,
9417524702,9463741635)
C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. 1ST, 2ND, 3RD & 4TH SEM, B.C.A., B.SC. COMPUTERS & I.T., PGDCA,
MCA, B.PHARMACY)

You might also like