82. Write a program to solve the problem of tower of Hanoi with given disk?

#include<iostream.h> #include<conio.h> void hanoi(int disk,char s,char t,char d) {                 if(disk==1)                                 {                                 cout<<"Move Disk "<<disk<<" From "<<s<<" To "<<d<<endl;                                 return;                                 }                 hanoi(disk-1,s,d,t);          //Recursive Function Call                 cout<<"Move Disk "<<disk<<" From "<<s<<" To "<<d<<endl;                 hanoi(disk-1,t,s,d);          //Recursive function call } void main() {                 char s='A',t='B',d='C';                 int disk;                ... Continue Reading →

Advertisements

81. Write a program to find the sum between two number using recursive function?

#include<iostream.h> #include<conio.h> int x; int add(int i) {                 if(i==x-1)                                 {                                 return 0;                                 }                 else                                 {                                 return(i+add(i-1));                                 } } void main() {                 int a,b,c;                 clrscr();                 cout<<"Enter Two Number : \n";                 cin>>a>>b;                 x=a;                 c=add(b);                 cout<<"The Sum Between "<<a<<" and "<<b<<" = "<<c<<endl;... Continue Reading →

80. Write a program to add two numbers using recursive function?

#include<iostream.h> #include<conio.h> int x; int add(int i) {                 if(i==0)                                 {                                 return x;                                 }                 else                                 {                                 return(1+add(i-1));                                 } } void main() {                 int a,b,c;                 clrscr();                 cout<<"Enter Two Number : \n";                 cin>>a>>b;                 x=a;                 c=add(b);                 cout<<"The Addition of "<<a<<" and "<<b<<" = "<<c<<endl;... Continue Reading →

79. Write a program to perform factorial of given number?

#include<iostream.h> #include<conio.h> long factorial(int i); void main() {                 int n,result;                 clrscr();                 cout<<"Enter A Number For Factorial : ";                 cin>>n;                 result=factorial(n);                 cout<<"The Factorial of "<<n<<" = "<<result<<endl;                 getch(); } long factorial(int i) {                 if(i==0)                                 {                                 return 1;                                 }                 else                                 {                                 return(i*factorial(i-1));                                ... Continue Reading →

78. Write a program to perform addition using function overloading technique?

  A. #include<iostream.h> #include<conio.h> void add(int a,int b); float add(double d,int i); void add(int p,int q,int r); void main() {                 float f;                 clrscr();                 add(10,5,3);                 f=add(10.5,25);                 add(30,5);                 cout<<"F : "<<f<<endl;                 getch(); } void add(int a,int b) {                 cout<<"A+B = "<<a+b<<endl; } float add(double d,int i) {                 return... Continue Reading →

77. Write a program to print the output of following program?

#include<iostream.h> #include<conio.h> void main() {                 int x=5,y=5,p,q;                 clrscr();                 p=++x + x++ + ++x;                 q=y++ + ++y + ++y + y++;                 cout<<"P : "<<p<<endl;                 cout<<"Q : "<<q<<endl;                 cout<<"X : "<<x<<endl;                 cout<<"Y : "<<y<<endl;                 getch(); }

76. Write a program to demonstrate inline function and macro to perform multiplication?

#include<iostream.h> #include<conio.h> #define MUL(a) a*a       //Macro Definition inline int mul(int a)          //Inline Function Definition {                 return(a*a); } void main() {                 int x=5,y=5,p,q;                 clrscr();                 p=mul(++x);       //Inline Function Call                 q=MUL(++y);     //Macro Call                 cout<<"The Multiplication From Inline Function : "<<p<<endl;                 cout<<"The Multiplication From Macro : "<<q<<endl;                 cout<<"X : "<<x<<endl;                ... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: