SlideShare a Scribd company logo
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
Program 1: write a program to find simple interest by using formula: SI=(p*r*t)/100?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int p, t;
float si, r;
clrscr();
printf("enter principal amount, rate and timen");
scanf("%d %d %f", &p, &t, &r);
si=(p*r*t)/100;
printf("n simple interest=%f", si);
getch();
}
Output: (For example if principal amount=100000, rate=10 and time=4.)
enter principal amount, rate and time
100000
10
4
simple interest=40000
Program 2: write a program for conversion of C°
temperature to F°
temperature?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
float f, c;
clrscr();
printf("enter temperature in C°
n");
scanf("%f", &c);
f=((9*c)/5)+32;
printf("temperature in F°
=%f", f);
getch();
}
Output: (For example if temperature= 10 C°
.)
enter temperature in C°
10
temperature in F°
=50
Inputpart
Processingpart
outputpart
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
Program 3: write a program to find greater number between two numbers?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf("enter two numbersn");
scanf("%d %d", &a, &b);
if(a>b)
{
printf("a=%d is greater than b=%d", a,b);
}
else
{
printf("b=%d is greater than a=%d", b,a);
}
getch();
}
Output: (For example if a=17 and b=12.)
enter two numbers
17
12
a=17 is greater than b=12
Program 4: write a program to find greater number between three numbers?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
clrscr();
printf("enter three numbersn");
scanf("%d %d %d", &a, &b, &c);
if((a>b)&&(a>c))
{
printf("a=%d is greater", a);
}
else
{
if(b>c)
{
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
printf("b=%d is greater", b);
}
else
{
printf("c=%d is greater", c);
}
}
getch();
}
Output: (For example if a=17, b=12 and c=89.)
enter three numbers
17
12
89
c=89 is greater
Program 5: write a program to find out the division of the student from marks of five subjects?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, d, e;
float avg;
clrscr();
printf("enter your marks in mathsn");
scanf("%d",&a);
printf("nenter your marks in sciencen");
scanf("%d",&b);
printf("nenter your marks in hindin");
scanf("%d",&c);
printf("nenter your marks in englishn");
scanf("%d",&d);
printf("nenter your marks in social studiesn");
scanf("%d",&e);
if((a<33)||(b<33)||(c<33)||(d<33)||(e<33))
{
printf("you are fail");
}
else
{
avg=(a+b+c+d+e)/5;
if(avg>=75)
{
printf("nfirst division");
}
else if((avg<75)&&(avg>=55))
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
{
printf("nsecond division");
}
else
{
printf("n third division");
}
}
getch();
}
Output: (for ex: marks In maths=92, science=85, hindi=88, english=82 and social studies=90.)
enter your marks in maths
92
enter your marks in science
85
enter your marks in hindi
88
enter your marks in english
82
enter your marks in social studies
90
first division
Program 6: write a program to calculate area and circumference of a circle as per user need?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x,r;
float a, c, p=3.14;
clrscr();
printf("choose your option:n press 1 to calculate area of a circle n press 2 to calculate
circumference of a circlen");
scanf("%d", &x);
if(x==1)
{
printf("enter radiusn");
scanf("%d",&r);
a=p*r*r;
printf("n area=%f",a);
}
else
{
printf("enter radiusn");
scanf("%d",&r);
c=2*p*r;
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
printf("n circumference=%f",c);
}
getch();
}
Output: (for ex: user want to calculate area of a circle and radius=7.)
choose your option:
press 1 to calculate area of a circle
press 2 to calculate circumference of a circle
1
enter radius
7
area=153.86
Program 7: write a program to calculate gross salary, if dearness allowance is 40% and house
rent allowance is 20% of the basic salary?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
float da,hra,gs,bs;
clrscr();
printf("enter your basic salary");
scanf("%f",&bs);
da=(bs*40/100);
hra=(bs*20/100);
gs=bs-hra-da;
printf("n your gross salary is=%f", gs);
getch();
}
Or;
#include<stdio.h>
#include<conio.h>
void main()
{
float da,hra,gs;
int bs;
clrscr();
printf("n enter your basic salary");
scanf("%d",&bs);
da=(0.4*bs);
hra=(0.2*bs);
gs=bs-hra-da;
printf("n your gross salary is=%f", gs);
getch();
}
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
Or;
#include<stdio.h>
#include<conio.h>
void main()
{
float da,hra,gs;
int bs;
clrscr();
printf("enter your basic salaryn");
scanf("%d",&bs);
da=(40.0/100)*bs;
hra=(20.0/100)*bs;
gs=bs-hra-da;
printf("n your gross salary is=%f", gs);
getch();
}
As, we have discussed integer float conversion previously:
You know if an integer value is divided by another integer value and in case the answer is float
type then also, only integer part of the answer we will get as result.
That’s why I had showed you three ways of calculating da and hra.
In first way; as bs itself is float type therefore, when it will be multiplied by 40 the result will be
considered as float type so that after division by100, We will get da=0.40000 (same thing apply
for hra.)
In second approach, as bs is integer type that’s why we have directly multiplied it 0.4 and 0.2.
because here, (bs*40/100); will not work. As, 40 (is integer type) and 100(is also integer type),
therefore, integer/ integer= integer. Due to which, 40/100=0 and bs*0=0. (same thing applies
with hra. )
In third approach; as bs in integer type that’s why we have written equations like;
da=(40.0/100)*bs;
hra=(20.0/100)*bs;
as, 40.0 is real type divided by 100(integer type ) and real/integer=real value.
Therefore, it will work perfectly;
40.0/100=0.40000
0.40000*bs= (required float value according to bs value.)
Output: (for ex: basic salary=25000)
enter your basic salary
25000
your gross salary is=10000.00
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
Program 8: write a program to identify vowels and consonants?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
char x;
clrscr();
printf("enter any alphabet in small casen");
scanf("%c", &x);
if(x=='a'||x=='e'|| x=='i'|| x=='o'|| x=='u')
{
printf("you have entered a vowel");
}
else
{
printf("you have entered a consonant");
}
getch();
}
Output: (for ex: user has entered a)
enter any alphabet in small case
a
you have entered a vowel
Program 9: write a program to identify even and odd number?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m;
clrscr();
printf("enter any integer type valuen");
scanf("%d", &n);
m=n%2;
if(m==0)
{
printf("number is even");
}
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
else
{
printf("number is odd");
}
getch();
}
Or;
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter any integer type value");
scanf("%d", &n);
if(n%2)
{
printf("number is odd");
}
else
{
printf("number is even");
}
getch();
}
In second approach we have used concept of 0 implies false and 1 implies true. Therefore;
when n%2=0, it will indicate false and control goes to else statement and in other cases if
statement will be executed.
Output: (for example user has entered 21)
enter any integer type value
21
number is odd
Explaination: (according to second approach)
as 21%2 is equal to 1 (moduls operator gives remainder). Therefore if statement will be
executed.
Program 10: write a program to swap two numbers without using third variable?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
clrscr();
printf("enter two numbers n");
scanf("%d%d",&a, &b);
printf("n before swap a=%d and b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("n after swap a=%d and b=%d",a,b);
getch();
}
Output: (for ex: a=25 and b=16)
enter two numbers
25
16
before swap a=25 and b=16
after swap a=16 and b=25
Program 11: write a program to swap two numbers using bitwise ex-or operator?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter two numbers n");
scanf("%d%d",&a, &b);
printf("n before swap a=%d and b=%d",a,b);
a=a^b;
b=a^b;
a=a^b;
printf("n after swap a=%d and b=%d",a,b);
getch();
}
Let us take an example to understand how this concept works:
Lets; a=5 and b=6, therefore;
a=a^b;
a= 0101
b= 0110
a^b=0011
Similarly; at second step:
b=a^b; and after first step a=3 and b=6
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
a= 0011
b= 0110
a^b=0101
now, a=3 and b=5
similarly, at third step:
a=a^b;
a= 0101
b= 0101
a^b=0110
now, a=6 and b=5. (This is our required answer.)
Output: (as: a=5 and b=6)
enter two numbers
5
6
before swap a=5 and b=6
after swap a=6 and b=5
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com

More Related Content

PDF
Chapter 5 exercises Balagurusamy Programming ANSI in c
PDF
Chapter 4 : Balagurusamy Programming ANSI in C
PDF
Chapter 6 Balagurusamy Programming ANSI in c
PDF
Chapter 3 : Balagurusamy Programming ANSI in C
PDF
Chapter 2 : Balagurusamy_ Programming ANsI in C
DOCX
Core programming in c
RTF
DOCX
Chapter 8 c solution
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 4 : Balagurusamy Programming ANSI in C
Chapter 6 Balagurusamy Programming ANSI in c
Chapter 3 : Balagurusamy Programming ANSI in C
Chapter 2 : Balagurusamy_ Programming ANsI in C
Core programming in c
Chapter 8 c solution

What's hot (20)

PPT
All important c programby makhan kumbhkar
DOCX
C Programming
DOC
C important questions
PDF
Numerical analysis
PDF
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DOC
C lab-programs
PDF
Revision1 C programming
DOCX
Let us c (by yashvant kanetkar) chapter 1 solution
PDF
important C questions and_answers praveensomesh
PPT
Input And Output
PDF
Revision1schema C programming
PPTX
Expressions using operator in c
DOC
Basic c programs updated on 31.8.2020
PDF
9 character string &amp; string library
PPTX
Decision making and branching
PPTX
FLOW OF CONTROL-NESTED IFS IN PYTHON
PPT
Functions and pointers_unit_4
PPTX
All important c programby makhan kumbhkar
C Programming
C important questions
Numerical analysis
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
C lab-programs
Revision1 C programming
Let us c (by yashvant kanetkar) chapter 1 solution
important C questions and_answers praveensomesh
Input And Output
Revision1schema C programming
Expressions using operator in c
Basic c programs updated on 31.8.2020
9 character string &amp; string library
Decision making and branching
FLOW OF CONTROL-NESTED IFS IN PYTHON
Functions and pointers_unit_4
Ad

Similar to programs of c www.eakanchha.com (20)

DOC
Programming egs
PDF
C faq pdf
DOCX
Cs291 assignment solution
PDF
Programming fundamental 02
PDF
Progr3
PDF
C programming Assignments and Questions.pdf
PPTX
Understand more about C
DOCX
DOCX
Practical write a c program to reverse a given number
DOCX
Practical write a c program to reverse a given number
DOCX
C Programming
DOCX
Qust & ans inc
DOCX
PPTX
Control structure of c
PPTX
comp2
DOCX
Best C Programming Solution
PPTX
Programming ppt files (final)
PPTX
the refernce of programming C notes ppt.pptx
PPTX
Introduction to Basic C programming 02
PDF
C programs
Programming egs
C faq pdf
Cs291 assignment solution
Programming fundamental 02
Progr3
C programming Assignments and Questions.pdf
Understand more about C
Practical write a c program to reverse a given number
Practical write a c program to reverse a given number
C Programming
Qust & ans inc
Control structure of c
comp2
Best C Programming Solution
Programming ppt files (final)
the refernce of programming C notes ppt.pptx
Introduction to Basic C programming 02
C programs
Ad

More from Akanchha Agrawal (7)

DOCX
Micro economics questions sets
DOCX
Number system with conversions www.eakanchha.com
DOCX
Basic of c programming www.eakanchha.com
PPTX
Lvp law of variable proportions www.eakanchha.com
PPTX
cost missing value question www.eakanchha.com
PPTX
cost missing value question www.eakanchha.com
PPTX
cost micro economics www.eakanchha.com
Micro economics questions sets
Number system with conversions www.eakanchha.com
Basic of c programming www.eakanchha.com
Lvp law of variable proportions www.eakanchha.com
cost missing value question www.eakanchha.com
cost missing value question www.eakanchha.com
cost micro economics www.eakanchha.com

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Updated Idioms and Phrasal Verbs in English subject
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
master seminar digital applications in india
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Lesson notes of climatology university.
What if we spent less time fighting change, and more time building what’s rig...
2.FourierTransform-ShortQuestionswithAnswers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Updated Idioms and Phrasal Verbs in English subject
Chinmaya Tiranga quiz Grand Finale.pdf
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Final Presentation General Medicine 03-08-2024.pptx
master seminar digital applications in india
LDMMIA Reiki Yoga Finals Review Spring Summer
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Yogi Goddess Pres Conference Studio Updates
Weekly quiz Compilation Jan -July 25.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
202450812 BayCHI UCSC-SV 20250812 v17.pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf

programs of c www.eakanchha.com

  • 1. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com
  • 2. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com Program 1: write a program to find simple interest by using formula: SI=(p*r*t)/100? Solution: #include<stdio.h> #include<conio.h> void main() { int p, t; float si, r; clrscr(); printf("enter principal amount, rate and timen"); scanf("%d %d %f", &p, &t, &r); si=(p*r*t)/100; printf("n simple interest=%f", si); getch(); } Output: (For example if principal amount=100000, rate=10 and time=4.) enter principal amount, rate and time 100000 10 4 simple interest=40000 Program 2: write a program for conversion of C° temperature to F° temperature? Solution: #include<stdio.h> #include<conio.h> void main() { float f, c; clrscr(); printf("enter temperature in C° n"); scanf("%f", &c); f=((9*c)/5)+32; printf("temperature in F° =%f", f); getch(); } Output: (For example if temperature= 10 C° .) enter temperature in C° 10 temperature in F° =50 Inputpart Processingpart outputpart
  • 3. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com Program 3: write a program to find greater number between two numbers? Solution: #include<stdio.h> #include<conio.h> void main() { int a, b; clrscr(); printf("enter two numbersn"); scanf("%d %d", &a, &b); if(a>b) { printf("a=%d is greater than b=%d", a,b); } else { printf("b=%d is greater than a=%d", b,a); } getch(); } Output: (For example if a=17 and b=12.) enter two numbers 17 12 a=17 is greater than b=12 Program 4: write a program to find greater number between three numbers? Solution: #include<stdio.h> #include<conio.h> void main() { int a, b, c; clrscr(); printf("enter three numbersn"); scanf("%d %d %d", &a, &b, &c); if((a>b)&&(a>c)) { printf("a=%d is greater", a); } else { if(b>c) {
  • 4. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com printf("b=%d is greater", b); } else { printf("c=%d is greater", c); } } getch(); } Output: (For example if a=17, b=12 and c=89.) enter three numbers 17 12 89 c=89 is greater Program 5: write a program to find out the division of the student from marks of five subjects? Solution: #include<stdio.h> #include<conio.h> void main() { int a, b, c, d, e; float avg; clrscr(); printf("enter your marks in mathsn"); scanf("%d",&a); printf("nenter your marks in sciencen"); scanf("%d",&b); printf("nenter your marks in hindin"); scanf("%d",&c); printf("nenter your marks in englishn"); scanf("%d",&d); printf("nenter your marks in social studiesn"); scanf("%d",&e); if((a<33)||(b<33)||(c<33)||(d<33)||(e<33)) { printf("you are fail"); } else { avg=(a+b+c+d+e)/5; if(avg>=75) { printf("nfirst division"); } else if((avg<75)&&(avg>=55))
  • 5. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com { printf("nsecond division"); } else { printf("n third division"); } } getch(); } Output: (for ex: marks In maths=92, science=85, hindi=88, english=82 and social studies=90.) enter your marks in maths 92 enter your marks in science 85 enter your marks in hindi 88 enter your marks in english 82 enter your marks in social studies 90 first division Program 6: write a program to calculate area and circumference of a circle as per user need? Solution: #include<stdio.h> #include<conio.h> void main() { int x,r; float a, c, p=3.14; clrscr(); printf("choose your option:n press 1 to calculate area of a circle n press 2 to calculate circumference of a circlen"); scanf("%d", &x); if(x==1) { printf("enter radiusn"); scanf("%d",&r); a=p*r*r; printf("n area=%f",a); } else { printf("enter radiusn"); scanf("%d",&r); c=2*p*r;
  • 6. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com printf("n circumference=%f",c); } getch(); } Output: (for ex: user want to calculate area of a circle and radius=7.) choose your option: press 1 to calculate area of a circle press 2 to calculate circumference of a circle 1 enter radius 7 area=153.86 Program 7: write a program to calculate gross salary, if dearness allowance is 40% and house rent allowance is 20% of the basic salary? Solution: #include<stdio.h> #include<conio.h> void main() { float da,hra,gs,bs; clrscr(); printf("enter your basic salary"); scanf("%f",&bs); da=(bs*40/100); hra=(bs*20/100); gs=bs-hra-da; printf("n your gross salary is=%f", gs); getch(); } Or; #include<stdio.h> #include<conio.h> void main() { float da,hra,gs; int bs; clrscr(); printf("n enter your basic salary"); scanf("%d",&bs); da=(0.4*bs); hra=(0.2*bs); gs=bs-hra-da; printf("n your gross salary is=%f", gs); getch(); }
  • 7. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com Or; #include<stdio.h> #include<conio.h> void main() { float da,hra,gs; int bs; clrscr(); printf("enter your basic salaryn"); scanf("%d",&bs); da=(40.0/100)*bs; hra=(20.0/100)*bs; gs=bs-hra-da; printf("n your gross salary is=%f", gs); getch(); } As, we have discussed integer float conversion previously: You know if an integer value is divided by another integer value and in case the answer is float type then also, only integer part of the answer we will get as result. That’s why I had showed you three ways of calculating da and hra. In first way; as bs itself is float type therefore, when it will be multiplied by 40 the result will be considered as float type so that after division by100, We will get da=0.40000 (same thing apply for hra.) In second approach, as bs is integer type that’s why we have directly multiplied it 0.4 and 0.2. because here, (bs*40/100); will not work. As, 40 (is integer type) and 100(is also integer type), therefore, integer/ integer= integer. Due to which, 40/100=0 and bs*0=0. (same thing applies with hra. ) In third approach; as bs in integer type that’s why we have written equations like; da=(40.0/100)*bs; hra=(20.0/100)*bs; as, 40.0 is real type divided by 100(integer type ) and real/integer=real value. Therefore, it will work perfectly; 40.0/100=0.40000 0.40000*bs= (required float value according to bs value.) Output: (for ex: basic salary=25000) enter your basic salary 25000 your gross salary is=10000.00
  • 8. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com Program 8: write a program to identify vowels and consonants? Solution: #include<stdio.h> #include<conio.h> void main() { char x; clrscr(); printf("enter any alphabet in small casen"); scanf("%c", &x); if(x=='a'||x=='e'|| x=='i'|| x=='o'|| x=='u') { printf("you have entered a vowel"); } else { printf("you have entered a consonant"); } getch(); } Output: (for ex: user has entered a) enter any alphabet in small case a you have entered a vowel Program 9: write a program to identify even and odd number? Solution: #include<stdio.h> #include<conio.h> void main() { int n,m; clrscr(); printf("enter any integer type valuen"); scanf("%d", &n); m=n%2; if(m==0) { printf("number is even"); }
  • 9. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com else { printf("number is odd"); } getch(); } Or; #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("enter any integer type value"); scanf("%d", &n); if(n%2) { printf("number is odd"); } else { printf("number is even"); } getch(); } In second approach we have used concept of 0 implies false and 1 implies true. Therefore; when n%2=0, it will indicate false and control goes to else statement and in other cases if statement will be executed. Output: (for example user has entered 21) enter any integer type value 21 number is odd Explaination: (according to second approach) as 21%2 is equal to 1 (moduls operator gives remainder). Therefore if statement will be executed. Program 10: write a program to swap two numbers without using third variable? Solution: #include<stdio.h> #include<conio.h> void main() { int a,b;
  • 10. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com clrscr(); printf("enter two numbers n"); scanf("%d%d",&a, &b); printf("n before swap a=%d and b=%d",a,b); a=a+b; b=a-b; a=a-b; printf("n after swap a=%d and b=%d",a,b); getch(); } Output: (for ex: a=25 and b=16) enter two numbers 25 16 before swap a=25 and b=16 after swap a=16 and b=25 Program 11: write a program to swap two numbers using bitwise ex-or operator? Solution: #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("enter two numbers n"); scanf("%d%d",&a, &b); printf("n before swap a=%d and b=%d",a,b); a=a^b; b=a^b; a=a^b; printf("n after swap a=%d and b=%d",a,b); getch(); } Let us take an example to understand how this concept works: Lets; a=5 and b=6, therefore; a=a^b; a= 0101 b= 0110 a^b=0011 Similarly; at second step: b=a^b; and after first step a=3 and b=6
  • 11. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com a= 0011 b= 0110 a^b=0101 now, a=3 and b=5 similarly, at third step: a=a^b; a= 0101 b= 0101 a^b=0110 now, a=6 and b=5. (This is our required answer.) Output: (as: a=5 and b=6) enter two numbers 5 6 before swap a=5 and b=6 after swap a=6 and b=5
  • 12. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com