21
C-Programming Variables, Constants and Expressions 1 B.Tech. 1 st , 2 nd , 3 rd & 4 th Sem, B.C.A., B.Sc. (Computers & I.T.), PGDCA, B.Pharmacy Teacher : Sandeep Sangwan (9417565720, 9417524702, 9463741635) S.C.F. – 204, 2 nd 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&T’s Bell Labs that was called B-Language. But it was also turned out to be very specific. CREATIVE INFOTECH, SCF-204(ABOVE CHANDIGARH SWEETS PVT. LTD.), 2 ND FLOOR, SEC-14, PKL(9417565720, 9417524702,9463741635) C, C++, DATA STRUCTURES, MATHEMATICS (B.TECH. – 1 ST , 2 ND , 3 RD & 4 TH SEM, B.C.A., B.SC. – COMPUTERS & I.T., PGDCA, MCA, B.PHARMACY)

01 Simple

  • Upload
    suhel

  • View
    3

  • Download
    1

Embed Size (px)

DESCRIPTION

c la

Citation preview

Page 1: 01 Simple

C-Programming Variables, Constants and Expressions 1

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&T’s 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)

Page 2: 01 Simple

C-Programming Variables, Constants and Expressions 2

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 fileconio.h : console input output header filevoid : 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 A, B, C, ……………..,Y, Za, b, c,…………………, y, z

Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9Special Symbols

~ ` ! @ # $ % ^ & * ( ) _ - + =| \ { } [ ] : ; “ ‘ < > , . ? /

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 doesn’t 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)

Page 3: 01 Simple

C-Programming Variables, Constants and Expressions 3

Types of C Constants :

C constants can be divided into two major categories:(a) Primary Constants(b) Secondary ConstantsThese constants are further categorized as follows:

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.00625A 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 Constants

Primary Constants Secondary Constants

Integer ConstantReal ConstantCharacter ConstantString constant

ArrayPointerStructureUnion

Page 4: 01 Simple

C-Programming Variables, Constants and Expressions 4

(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 Range Size Format

signed char -128 to +127 1 Byte %c

Unsigned char 0 to 255 1 Byte %c

short int

or int

or short signed int

-32768 to +32767 2 Bytes %d

short unsigned int 0 to 216

i.e. 0 to 65536

2 Bytes %u

long signed int -231 to (231-1) 4 Bytes

or 31 bits

%ld

long unsigned int 0 to (232 – 1) 4 Bytes

or 32 bits

%lu

float -231 to (231-1) 4 Bytes %f

double (long float) -263 to (263-1) 8 Bytes %lf

long double -279 to +(279-1) 10 Bytes %Lf

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

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)

Page 5: 01 Simple

C-Programming Variables, Constants and Expressions 5

VARIABLE

“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 declarationfloat per ; // Floating point number variables declarationdouble balance, profit, loss ; // double variables declarationchar nm1, nm2; // Character variables declarationchar 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 Incorrectcount 1counttest23 hi!therehigh_bal high…balance

In an identifier, uppercase and lowercase are treated as different. Hence, count, Count and COUNT are three separate identifiers.

KEYWORDS

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)

Page 6: 01 Simple

C-Programming Variables, Constants and Expressions 6

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 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 double if staticbreak else int structcase enum long switchchar extern near typedefconst float register unioncontinue far return unsigneddefault for short voiddo goto signed 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. Arithmetic Operators2. Relational Operators3. Logical Operators4. Ternary Operators5. Increment and Decrement Operators

1. 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.

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)

Page 7: 01 Simple

C-Programming Variables, Constants and Expressions 7

Operator Meaning+ 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)

Page 8: 01 Simple

C-Programming Variables, Constants and Expressions 8

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>

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)

Page 9: 01 Simple

C-Programming Variables, Constants and Expressions 9

#include<conio.h>void main( ){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 variableprintf("\nGiven integer is : %d",num);getch( );}

Prog. 5 : WAP for Floating point number Initialization

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)

Page 10: 01 Simple

C-Programming Variables, Constants and Expressions 10

#include<stdio.h>#include<conio.h>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

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)

Page 11: 01 Simple

C-Programming Variables, Constants and Expressions 11

#include<stdio.h>#include<conio.h>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>

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)

Page 12: 01 Simple

C-Programming Variables, Constants and Expressions 12

#include<conio.h>void main(){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>

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)

Page 13: 01 Simple

C-Programming Variables, Constants and Expressions 13

void main( ){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;

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)

Page 14: 01 Simple

C-Programming Variables, Constants and Expressions 14

printf("Enter radius of circle : ");scanf("%f",&rad);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));

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)

Page 15: 01 Simple

C-Programming Variables, Constants and Expressions 15

getch( );}

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 Integerint n;printf("Enter an integer : ");scanf("%d",&n);printf("\nAbsolute value of %d is : %d",n,abs(n));

// Absolute value of Floating pt. numberfloat num;printf("\n\nEnter a floating pt. number : ");scanf("%f",&num);printf("\nAbsolute value of %.2f is : %.2f",num,fabs(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)

Page 16: 01 Simple

C-Programming Variables, Constants and Expressions 16

Prog. 20 : WAP to determine the area of a triangle by using Hero's formula.

#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;

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)

Page 17: 01 Simple

C-Programming Variables, Constants and Expressions 17

printf("Enter two numbers a and b : ");scanf("%d%d",&a,&b);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)